CodeMemberProperty Class
Assembly: System (in system.dll)
[SerializableAttribute] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] [ComVisibleAttribute(true)] public class CodeMemberProperty : CodeTypeMember
/** @attribute SerializableAttribute() */ /** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ /** @attribute ComVisibleAttribute(true) */ public class CodeMemberProperty extends CodeTypeMember
SerializableAttribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) ComVisibleAttribute(true) public class CodeMemberProperty extends CodeTypeMember
Not applicable.
CodeMemberProperty can be used to represent the declaration for a property of a type.
The Type property specifies the data type of the property. The GetStatements property contains any get statement methods for the property. The SetStatements property contains any set statement methods for the property. The Parameters property specifies any parameters for the property, such as are required for an indexer property.
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 = 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 = 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 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.