CodeTypeConstructor Class
Represents a static constructor for a class.
For a list of all members of this type, see CodeTypeConstructor Members.
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeTypeMember
System.CodeDom.CodeMemberMethod
System.CodeDom.CodeTypeConstructor
[Visual Basic] <Serializable> <ClassInterface(ClassInterfaceType.AutoDispatch)> <ComVisible(True)> Public Class CodeTypeConstructor Inherits CodeMemberMethod [C#] [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] public class CodeTypeConstructor : CodeMemberMethod [C++] [Serializable] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ComVisible(true)] public __gc class CodeTypeConstructor : public CodeMemberMethod [JScript] public Serializable ClassInterface(ClassInterfaceType.AutoDispatch) ComVisible(true) class CodeTypeConstructor extends CodeMemberMethod
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
CodeTypeConstructor can be used to represent the static constructor for a class. A static constructor is called once when the type is loaded.
Note Not all languages support static constructors. Support for static constructors can be checked by calling Supports with the StaticConstructors flag to determine if static constructors are supported by the code generator for a particular language.
Example
[Visual Basic, C#, C++] The following example demonstrates use of a CodeTypeConstructor to declare a static constructor for a type.
[Visual Basic] ' Declares a new type for a static constructor. Dim type1 As New CodeTypeDeclaration("Type1") ' Declares a static constructor. Dim constructor2 As New CodeTypeConstructor() ' Adds the static constructor to the type. type1.Members.Add(constructor2) ' A Visual Basic code generator produces the following source code for the preceeding example code: ' Public Class Type1 ' ' Shared Sub New() ' End Sub ' End Class [C#] // Declares a new type for a static constructor. CodeTypeDeclaration type1 = new CodeTypeDeclaration("Type1"); // Declares a static constructor. CodeTypeConstructor constructor2 = new CodeTypeConstructor(); // Adds the static constructor to the type. type1.Members.Add( constructor2 ); // A C# code generator produces the following source code for the preceeding example code: // public class Type1 // { // // static Type1() // { // } // } [C++] // Declares a new type for a static constructor. CodeTypeDeclaration* type1 = new CodeTypeDeclaration(S"Type1"); // Declares a static constructor. CodeTypeConstructor* constructor2 = new CodeTypeConstructor(); // Adds the static constructor to the type. type1->Members->Add( constructor2 ); // A C# code generator produces the following source code for the preceeding example code: // public class Type1 // { // // static Type1() // { // } // }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.CodeDom
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
See Also
CodeTypeConstructor Members | System.CodeDom Namespace | CodeConstructor