CodeMemberProperty 类

定义

表示某种类型的属性的声明。Represents a declaration for a property of a type.

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

示例

下面CodeMemberProperty的代码示例演示如何使用来string定义具有getset访问器的属性。The following example code demonstrates use of a CodeMemberProperty to define a string property with get and set accessors.

// Declares a property of type String named StringProperty.
CodeMemberProperty^ property1 = gcnew CodeMemberProperty;
property1->Name = "StringProperty";
property1->Type = gcnew CodeTypeReference( "System.String" );
property1->Attributes = MemberAttributes::Public;
property1->GetStatements->Add( gcnew CodeMethodReturnStatement( gcnew CodeFieldReferenceExpression( gcnew CodeThisReferenceExpression,"testStringField" ) ) );
property1->SetStatements->Add( gcnew CodeAssignStatement( gcnew CodeFieldReferenceExpression( gcnew CodeThisReferenceExpression,"testStringField" ),gcnew CodePropertySetValueReferenceExpression ) );

// A C# code generator produces the following source code for the preceeding example code:
//       public virtual string StringProperty
//       {
//              get
//            {
//                return this.testStringField;
//            }
//            set
//            {
//                this.testStringField = value;
//            }
//       }
// Declares a property of type String named StringProperty.
CodeMemberProperty property1 = new CodeMemberProperty();
property1.Name = "StringProperty";
property1.Type = new CodeTypeReference("System.String");
property1.Attributes = MemberAttributes.Public;
property1.GetStatements.Add( new CodeMethodReturnStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "testStringField") ) );
property1.SetStatements.Add( new CodeAssignStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "testStringField"), new CodePropertySetValueReferenceExpression()));

// A C# code generator produces the following source code for the preceeding example code:

//       public virtual string StringProperty 
//       {
//              get 
//            {
//                return this.testStringField;
//            }
//            set 
//            {
//                this.testStringField = value;
//            }
//       }            
' Declares a property of type String named StringProperty.
Dim property1 As New CodeMemberProperty()
property1.Name = "StringProperty"
property1.Type = New CodeTypeReference("System.String")
property1.Attributes = MemberAttributes.Public
property1.GetStatements.Add(New CodeMethodReturnStatement(New CodeFieldReferenceExpression(New CodeThisReferenceExpression(), "testStringField")))
property1.SetStatements.Add(New CodeAssignStatement(New CodeFieldReferenceExpression(New CodeThisReferenceExpression(), "testStringField"), New CodePropertySetValueReferenceExpression()))

' A Visual Basic code generator produces the following source code for the preceeding example code:

'     Public Overridable Property StringProperty() As String
'         Get
'             Return Me.testStringField
'         End Get
'         Set(ByVal Value As String)
'             Me.testStringField = value
'         End Set
'     End Property

注解

CodeMemberProperty可用于表示某个类型的属性的声明。CodeMemberProperty can be used to represent the declaration for a property of a type.

Type属性指定属性的数据类型。The Type property specifies the data type of the property. GetStatements属性包含属性的所有 get 语句方法。The GetStatements property contains any get statement methods for the property. SetStatements属性包含属性的任何 set 语句方法。The SetStatements property contains any set statement methods for the property. Parameters属性指定属性的任何参数, 如索引器属性所需的参数。The Parameters property specifies any parameters for the property, such as are required for an indexer property.

构造函数

CodeMemberProperty()

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

属性

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)
GetStatements

获取该属性的 get 语句的集合。Gets the collection of get statements for the property.

HasGet

获取或设置指示该属性是否具有 get 方法访问器的值。Gets or sets a value indicating whether the property has a get method accessor.

HasSet

获取或设置指示该属性是否具有 set 方法访问器的值。Gets or sets a value indicating whether the property has a set method accessor.

ImplementationTypes

获取该属性实现的任何接口的数据类型。Gets the data types of any interfaces that the property implements.

LinePragma

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

(继承自 CodeTypeMember)
Name

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

(继承自 CodeTypeMember)
Parameters

获取该属性的声明表达式的集合。Gets the collection of declaration expressions for the property.

PrivateImplementationType

获取或设置该属性(如果是私有的)实现的接口的数据类型(如果有)。Gets or sets the data type of the interface, if any, this property, if private, implements.

SetStatements

获取该属性的 set 语句的集合。Gets the collection of set statements for the property.

StartDirectives

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

(继承自 CodeTypeMember)
Type

获取或设置属性的数据类型。Gets or sets the data type of the property.

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)

适用于