CodeMemberField 类

定义

表示某种类型的字段的声明。Represents a declaration for a field of a type.

public ref class CodeMemberField : System::CodeDom::CodeTypeMember
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeMemberField : System.CodeDom.CodeTypeMember
type CodeMemberField = class
    inherit CodeTypeMember
Public Class CodeMemberField
Inherits CodeTypeMember
继承
CodeMemberField
属性

示例

下面的示例演示CodeMemberField如何使用声明名为testStringField的类型string为的字段。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 = gcnew CodeTypeDeclaration( "FieldTest" );

// Declares a field of type String named testStringField.
CodeMemberField^ field1 = gcnew CodeMemberField( "System.String","TestStringField" );
type1->Members->Add( field1 );

// Declares an empty type constructor.
CodeConstructor^ constructor1 = gcnew 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.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.
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

// 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 = gcnew CodeMemberField( int::typeid,"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 = (MemberAttributes)((constPublicField->Attributes &  ~MemberAttributes::AccessMask &  ~MemberAttributes::ScopeMask) | MemberAttributes::Public | MemberAttributes::Const);
// 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;
' 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

注解

CodeMemberField可用于表示类型字段的声明。CodeMemberField can be used to represent the declaration for a field of a type.

构造函数

CodeMemberField()

初始化 CodeMemberField 类的新实例。Initializes a new instance of the CodeMemberField class.

CodeMemberField(CodeTypeReference, String)

使用指定的字段类型和字段名初始化 CodeMemberField 类的新实例。Initializes a new instance of the CodeMemberField class using the specified field type and field name.

CodeMemberField(String, String)

使用指定的字段类型和字段名初始化 CodeMemberField 类的新实例。Initializes a new instance of the CodeMemberField class using the specified field type and field name.

CodeMemberField(Type, String)

使用指定的字段类型和字段名初始化 CodeMemberField 类的新实例。Initializes a new instance of the CodeMemberField class using the specified field type and field name.

属性

Attributes

获取或设置成员的特性。Gets or sets the attributes of the member.

(继承自 CodeTypeMember)
Comments

获取类型成员的注释集合。Gets the collection of comments for the type member.

(继承自 CodeTypeMember)
CustomAttributes

获取或设置成员的自定义特性。Gets or sets the custom attributes of the member.

(继承自 CodeTypeMember)
EndDirectives

获取成员的结束指令。Gets the end directives for the member.

(继承自 CodeTypeMember)
InitExpression

获取或设置字段的初始化表达式。Gets or sets the initialization expression for the field.

LinePragma

获取或设置类型成员语句所在的行。Gets or sets the line on which the type member statement occurs.

(继承自 CodeTypeMember)
Name

获取或设置成员名。Gets or sets the name of the member.

(继承自 CodeTypeMember)
StartDirectives

获取成员的开始指令。Gets the start directives for the member.

(继承自 CodeTypeMember)
Type

获取或设置字段的类型。Gets or sets the type of the field.

UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于