Export (0) Print
Expand All

CodeTypeDelegate Class

Represents a delegate declaration.

Namespace:  System.CodeDom
Assembly:  System (in System.dll)

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeTypeDelegate : CodeTypeDeclaration

The CodeTypeDelegate type exposes the following members.

  NameDescription
Public methodCodeTypeDelegate()Initializes a new instance of the CodeTypeDelegate class.
Public methodCodeTypeDelegate(String)Initializes a new instance of the CodeTypeDelegate class.
Top

  NameDescription
Public propertyAttributesGets or sets the attributes of the member. (Inherited from CodeTypeMember.)
Public propertyBaseTypesGets the base types of the type. (Inherited from CodeTypeDeclaration.)
Public propertyCommentsGets the collection of comments for the type member. (Inherited from CodeTypeMember.)
Public propertyCustomAttributesGets or sets the custom attributes of the member. (Inherited from CodeTypeMember.)
Public propertyEndDirectivesGets the end directives for the member. (Inherited from CodeTypeMember.)
Public propertyIsClassGets or sets a value indicating whether the type is a class or reference type. (Inherited from CodeTypeDeclaration.)
Public propertyIsEnumGets or sets a value indicating whether the type is an enumeration. (Inherited from CodeTypeDeclaration.)
Public propertyIsInterfaceGets or sets a value indicating whether the type is an interface. (Inherited from CodeTypeDeclaration.)
Public propertyIsPartialGets or sets a value indicating whether the type declaration is complete or partial. (Inherited from CodeTypeDeclaration.)
Public propertyIsStructGets or sets a value indicating whether the type is a value type (struct). (Inherited from CodeTypeDeclaration.)
Public propertyLinePragmaGets or sets the line on which the type member statement occurs. (Inherited from CodeTypeMember.)
Public propertyMembersGets the collection of class members for the represented type. (Inherited from CodeTypeDeclaration.)
Public propertyNameGets or sets the name of the member. (Inherited from CodeTypeMember.)
Public propertyParametersGets the parameters of the delegate.
Public propertyReturnTypeGets or sets the return type of the delegate.
Public propertyStartDirectivesGets the start directives for the member. (Inherited from CodeTypeMember.)
Public propertyTypeAttributesGets or sets the attributes of the type. (Inherited from CodeTypeDeclaration.)
Public propertyTypeParametersGets the type parameters for the type declaration. (Inherited from CodeTypeDeclaration.)
Public propertyUserDataGets the user-definable data for the current object. (Inherited from CodeObject.)
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventPopulateBaseTypesOccurs when the BaseTypes collection is accessed for the first time. (Inherited from CodeTypeDeclaration.)
Public eventPopulateMembersOccurs when the Members collection is accessed for the first time. (Inherited from CodeTypeDeclaration.)
Top

CodeTypeDelegate can be used to declare a delegate type, or event handler. A delegate defines a method signature that can be used by calback methods or event handlers. Delegates can be declared at the namespace level or nested inside other types. Delegates cannot be nested inside other delegates.

The ReturnType property specifies the data type of the event handler returned by the delegate. The Parameters property contains the parameters for the delegate type.

CodeTypeDelegate should not be used for enumeration, interface, or type declaration. Instead, use CodeTypeDeclaration for those.

NoteNote

Not all languages support the declaration of delegates. Call the Supports method with the DeclareDelegates flag to determine if it is supported in a particular language.

The following example code demonstrates use of a CodeTypeDelegate to declare a new delegate type.

// Declares a delegate type called TestDelegate with an EventArgs parameter.
CodeTypeDelegate delegate1 = new CodeTypeDelegate("TestDelegate");            
delegate1.Parameters.Add( new CodeParameterDeclarationExpression("System.Object", "sender") );
delegate1.Parameters.Add( new CodeParameterDeclarationExpression("System.EventArgs", "e") );        

// A C# code generator produces the following source code for the preceeding example code: 

//     public delegate void TestDelegate(object sender, System.EventArgs e);

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft