This topic has not yet been rated - Rate this topic

CodeTypeDelegate Class

Represents a delegate declaration.

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeTypeMember
      System.CodeDom.CodeTypeDeclaration
        System.CodeDom.CodeTypeDelegate

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.

  Name Description
Public method CodeTypeDelegate() Initializes a new instance of the CodeTypeDelegate class.
Public method CodeTypeDelegate(String) Initializes a new instance of the CodeTypeDelegate class.
Top
  Name Description
Public property Attributes Gets or sets the attributes of the member. (Inherited from CodeTypeMember.)
Public property BaseTypes Gets the base types of the type. (Inherited from CodeTypeDeclaration.)
Public property Comments Gets the collection of comments for the type member. (Inherited from CodeTypeMember.)
Public property CustomAttributes Gets or sets the custom attributes of the member. (Inherited from CodeTypeMember.)
Public property EndDirectives Gets the end directives for the member. (Inherited from CodeTypeMember.)
Public property IsClass Gets or sets a value indicating whether the type is a class or reference type. (Inherited from CodeTypeDeclaration.)
Public property IsEnum Gets or sets a value indicating whether the type is an enumeration. (Inherited from CodeTypeDeclaration.)
Public property IsInterface Gets or sets a value indicating whether the type is an interface. (Inherited from CodeTypeDeclaration.)
Public property IsPartial Gets or sets a value indicating whether the type declaration is complete or partial. (Inherited from CodeTypeDeclaration.)
Public property IsStruct Gets or sets a value indicating whether the type is a value type (struct). (Inherited from CodeTypeDeclaration.)
Public property LinePragma Gets or sets the line on which the type member statement occurs. (Inherited from CodeTypeMember.)
Public property Members Gets the collection of class members for the represented type. (Inherited from CodeTypeDeclaration.)
Public property Name Gets or sets the name of the member. (Inherited from CodeTypeMember.)
Public property Parameters Gets the parameters of the delegate.
Public property ReturnType Gets or sets the return type of the delegate.
Public property StartDirectives Gets the start directives for the member. (Inherited from CodeTypeMember.)
Public property TypeAttributes Gets or sets the attributes of the type. (Inherited from CodeTypeDeclaration.)
Public property TypeParameters Gets the type parameters for the type declaration. (Inherited from CodeTypeDeclaration.)
Public property UserData Gets the user-definable data for the current object. (Inherited from CodeObject.)
Top
  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public event PopulateBaseTypes Occurs when the BaseTypes collection is accessed for the first time. (Inherited from CodeTypeDeclaration.)
Public event PopulateMembers Occurs 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.

Note Note

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, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ