CodeMemberProperty CodeMemberProperty CodeMemberProperty CodeMemberProperty Class

定義

表示型別屬性的宣告。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代碼示範如何使用來定義具有getstring set存取子的屬性。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() CodeMemberProperty() CodeMemberProperty()

初始化 CodeMemberProperty 類別的新執行個體。Initializes a new instance of the CodeMemberProperty class.

屬性

Attributes Attributes Attributes Attributes

取得或設定成員的屬性 (Attribute)。Gets or sets the attributes of the member.

(Inherited from CodeTypeMember)
Comments Comments Comments Comments

取得型別成員的註解集合。Gets the collection of comments for the type member.

(Inherited from CodeTypeMember)
CustomAttributes CustomAttributes CustomAttributes CustomAttributes

取得或設定成員的自訂屬性。Gets or sets the custom attributes of the member.

(Inherited from CodeTypeMember)
EndDirectives EndDirectives EndDirectives EndDirectives

取得成員的結尾指示詞。Gets the end directives for the member.

(Inherited from CodeTypeMember)
GetStatements GetStatements GetStatements GetStatements

取得屬性的 get 陳述式集合。Gets the collection of get statements for the property.

HasGet HasGet HasGet HasGet

取得或設定數值,表示屬性是否有 get 方法存取子。Gets or sets a value indicating whether the property has a get method accessor.

HasSet HasSet HasSet HasSet

取得或設定數值,表示屬性是否有 set 方法存取子。Gets or sets a value indicating whether the property has a set method accessor.

ImplementationTypes ImplementationTypes ImplementationTypes ImplementationTypes

取得屬性實作之任何介面的資料型別。Gets the data types of any interfaces that the property implements.

LinePragma LinePragma LinePragma LinePragma

取得或設定型別成員陳述式 (Statement) 所在的行。Gets or sets the line on which the type member statement occurs.

(Inherited from CodeTypeMember)
Name Name Name Name

取得或設定成員的名稱。Gets or sets the name of the member.

(Inherited from CodeTypeMember)
Parameters Parameters Parameters Parameters

取得屬性的宣告運算式集合。Gets the collection of declaration expressions for the property.

PrivateImplementationType PrivateImplementationType PrivateImplementationType PrivateImplementationType

取得或設定這個屬性 (如果是私用) 實作之介面的資料型別 (如果有的話)。Gets or sets the data type of the interface, if any, this property, if private, implements.

SetStatements SetStatements SetStatements SetStatements

取得屬性的 set 陳述式集合。Gets the collection of set statements for the property.

StartDirectives StartDirectives StartDirectives StartDirectives

取得成員的開頭指示詞。Gets the start directives for the member.

(Inherited from CodeTypeMember)
Type Type Type Type

取得或設定屬性的資料型別。Gets or sets the data type of the property.

UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於