This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
Defining a Constructor
A constructor is defined using the TypeBuilder.DefineConstructor method. DefineConstructor returns a ConstructorBuilder object. DefineConstructor requires the caller to specify the constructor attributes using the enum MethodAttributes.
The default constructor for a class is defined using the TypeBuilder.DefineDefaultConstructor method. DefineDefaultConstructor returns a ConstructorBuilder object. The default constructor simply calls the constructor of the parent class. The runtime will automatically define a default constructor for a class if the caller does not define a constructor for the class.
Attributes
- The runtime sets the attributes MethodAttributes.SpecialName and MethodAttributes.RTSpecialName for the constructor.
- Private constructors are specified using the MethodAttributes.Private attribute. For other visibility attributes see the description of the MethodAttributes enum.
Known Issues
- Although ConstructorBuilder is a subclass of ConstructorInfo, some of the abstract methods defined in the ConstructorInfo class are not fully implemented in ConstructorBuilder. These ConstructorBuilder methods throw the NotSupportedException. The desired functionality can be obtained by retrieving the type containing the constructor and reflecting on it. For example the ConstructorBuilder.Invoke method is not fully implemented.
- Custom modifiers are not currently supported.