CodeMemberProperty クラス
アセンブリ: System (system.dll 内)

<SerializableAttribute> _ <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ <ComVisibleAttribute(True)> _ Public Class CodeMemberProperty Inherits CodeTypeMember
[SerializableAttribute] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] [ComVisibleAttribute(true)] public class CodeMemberProperty : CodeTypeMember
[SerializableAttribute] [ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] [ComVisibleAttribute(true)] public ref class CodeMemberProperty : public CodeTypeMember

CodeMemberProperty を使用して、型のプロパティの宣言を表すことができます。
Type プロパティは、プロパティのデータ型を指定します。GetStatements プロパティには、プロパティの get ステートメントの各メソッドを格納します。SetStatements プロパティには、プロパティの set ステートメントの各メソッドを格納します。Parameters プロパティは、(たとえば、インデクサ プロパティで必要になるような) プロパティのパラメータを指定します。

CodeMemberProperty を使用して、get アクセサと set アクセサを持つ string プロパティ定義するコード例を次に示します。
' 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
// 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. 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.set_Name("StringProperty"); property1.set_Type(new CodeTypeReference("System.String")); property1.set_Attributes(MemberAttributes.Public); property1.get_GetStatements().Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression() , "testStringField"))); property1.get_SetStatements().Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression() , "testStringField"), new CodePropertySetValueReferenceExpression())); // /** @property // */ // public String get_StringProperty() // { // return this.get_testStringField(); // } //get_StringProperty // // /** @property // */ // public void set_StringProperty (String value ) // { // this.set_testStringField(value); // } //set_StringProperty

System.CodeDom.CodeObject
System.CodeDom.CodeTypeMember
System.CodeDom.CodeMemberProperty


Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- CodeMemberProperty クラスのページへのリンク