CodeMemberField Class
Represents a declaration for a field of a type.
For a list of all members of this type, see CodeMemberField Members.
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeTypeMember
System.CodeDom.CodeMemberField
[Visual Basic] <Serializable> <ClassInterface(ClassInterfaceType.AutoDispatch)> <ComVisible(True)> Public Class CodeMemberField Inherits CodeTypeMember [C#] [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] public class CodeMemberField : CodeTypeMember [C++] [Serializable] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ComVisible(true)] public __gc class CodeMemberField : public CodeTypeMember [JScript] public Serializable ClassInterface(ClassInterfaceType.AutoDispatch) ComVisible(true) class CodeMemberField extends CodeTypeMember
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
CodeMemberField can be used to represent the declaration for a field of a type.
Example
[Visual Basic, C#, C++] The following example demonstrates use of a CodeMemberField to declare a field of type string named testStringField.
[Visual Basic] ' Declares a type to contain a field and a constructor method. Dim type1 As New CodeTypeDeclaration("FieldTest") ' Declares a field of type String named testStringField. Dim field1 As New CodeMemberField("System.String", "testStringField") type1.Members.Add(field1) ' Declares an empty type constructor. Dim constructor1 As New CodeConstructor() constructor1.Attributes = MemberAttributes.Public type1.Members.Add(constructor1) ' A Visual Basic code generator produces the following source code for the preceeding example code: ' Public Class FieldTest ' ' Private TestStringField As String ' ' Public Sub New() ' MyBase.New() ' End Sub ' ' End Class [C#] // Declares a type to contain a field and a constructor method. CodeTypeDeclaration type1 = new CodeTypeDeclaration("FieldTest"); // Declares a field of type String named testStringField. CodeMemberField field1 = new CodeMemberField("System.String", "TestStringField"); type1.Members.Add( field1 ); // Declares an empty type constructor. CodeConstructor constructor1 = new CodeConstructor(); constructor1.Attributes = MemberAttributes.Public; type1.Members.Add( constructor1 ); // A C# code generator produces the following source code for the preceeding example code: // public class FieldTest // { // private string testStringField; // // public FieldTest() // { // } // } [C++] // Declares a type to contain a field and a constructor method. CodeTypeDeclaration* type1 = new CodeTypeDeclaration(S"FieldTest"); // Declares a field of type String named testStringField. CodeMemberField* field1 = new CodeMemberField(S"System.String", S"TestStringField"); type1->Members->Add( field1 ); // Declares an empty type constructor. CodeConstructor* constructor1 = new CodeConstructor(); constructor1->Attributes = MemberAttributes::Public; type1->Members->Add( constructor1 ); // A C# code generator produces the following source code for the preceeding example code: // public class FieldTest // { // private string testStringField; // // public FieldTest() // { // } // } [Visual Basic] ' This example demonstrates declaring a public constant type member field. ' When declaring a public constant type member field, you must set a particular ' access and scope mask to the member attributes of the field in order for the ' code generator to properly generate the field as a constant field. ' Declares an integer field using a CodeMemberField Dim constPublicField As New CodeMemberField(GetType(Integer), "testConstPublicField") ' Resets the access and scope mask bit flags of the member attributes of the field ' before setting the member attributes of the field to public and constant. constPublicField.Attributes = constPublicField.Attributes And Not MemberAttributes.AccessMask And Not MemberAttributes.ScopeMask Or MemberAttributes.Public Or MemberAttributes.Const [C#] // This example demonstrates declaring a public constant type member field. // When declaring a public constant type member field, you must set a particular // access and scope mask to the member attributes of the field in order for the // code generator to properly generate the field as a constant field. // Declares an integer field using a CodeMemberField CodeMemberField constPublicField = new CodeMemberField(typeof(int), "testConstPublicField"); // Resets the access and scope mask bit flags of the member attributes of the field // before setting the member attributes of the field to public and constant. constPublicField.Attributes = (constPublicField.Attributes & ~MemberAttributes.AccessMask & ~MemberAttributes.ScopeMask) | MemberAttributes.Public | MemberAttributes.Const; [C++] // This example demonstrates declaring a public constant type member field. // When declaring a public constant type member field, you must set a particular // access and scope mask to the member attributes of the field in order for the // code generator to properly generate the field as a constant field. // Declares an integer field using a CodeMemberField CodeMemberField* constPublicField = new CodeMemberField(__typeof(int), S"testConstPublicField"); // Resets the access and scope mask bit flags of the member attributes of the field // before setting the member attributes of the field to public and constant. constPublicField->Attributes = static_cast<MemberAttributes> ((constPublicField->Attributes & ~MemberAttributes::AccessMask & ~MemberAttributes::ScopeMask) | MemberAttributes::Public | MemberAttributes::Const);
[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)