Export (0) Print
Expand All

CodeMemberField Class

Represents a declaration for a field of a type.

Namespace: System.CodeDom
Assembly: System (in system.dll)

[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class CodeMemberField : CodeTypeMember
/** @attribute SerializableAttribute() */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class CodeMemberField extends CodeTypeMember
SerializableAttribute 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class CodeMemberField extends CodeTypeMember
Not applicable.

CodeMemberField can be used to represent the declaration for a field of a type.

The following example demonstrates use of a CodeMemberField to declare a field of type string named testStringField.

// 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() 
//        {
//        }                            
//    }            

// 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.get_Members().Add(field1);
// Declares an empty type constructor.
CodeConstructor constructor1 = new CodeConstructor();
constructor1.set_Attributes(MemberAttributes.Public);
type1.get_Members().Add(constructor1);
// A VJ# code generator produces the following source code for the 
// preceeding example code:
//    public class FieldTest 
//    {
//        private String testStringField;
//        
//        public FieldTest() 
//        {
//        } //FieldTest                            
//    } //FieldTest           

// 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;

System.Object
   System.CodeDom.CodeObject
     System.CodeDom.CodeTypeMember
      System.CodeDom.CodeMemberField

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft