Represents a declaration for a property of a type.
For a list of all members of this type, see CodeMemberProperty Members.
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeTypeMember
System.CodeDom.CodeMemberProperty
[Visual Basic] <Serializable> <ClassInterface(ClassInterfaceType.AutoDispatch)> <ComVisible(True)> Public Class CodeMemberProperty Inherits CodeTypeMember [C#] [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] public class CodeMemberProperty : CodeTypeMember [C++] [Serializable] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ComVisible(true)] public __gc class CodeMemberProperty : public CodeTypeMember [JScript] public Serializable ClassInterface(ClassInterfaceType.AutoDispatch) ComVisible(true) class CodeMemberProperty extends CodeTypeMember
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
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.
[Visual Basic, C#] The following example code demonstrates use of a CodeMemberProperty to define a string property with get and set accessors.
[Visual Basic] ' 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 [C#] // 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; // } // }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System.CodeDom
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)