CodeConstructor constructor = new CodeConstructor(); constructor.Attributes = MemberAttributes.Public; constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "value")); constructor.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "intValue"), new CodeArgumentReferenceExpression("value")));
CodeConstructor constructor = new CodeConstructor(); constructor.Attributes = MemberAttributes.Public; constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "value")); constructor.BaseConstructorArgs.Add(new CodeArgumentReferenceExpression("value")); constructor.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "intValue"), new CodeArgumentReferenceExpression("value")));In this example, we create a CodeConstructor object with the same access level and parameter as in Example 1, but we also add a call to the base constructor using the BaseConstructorArgs collection. We then assign the parameter value to a field in the class as before. Package Library: The CodeDom namespace is part of the .NET Class Library, which is included in the .NET Framework installation.