This documentation is archived and is not being maintained.

CodeMemberField Class

Represents a declaration for a field of a type.

Namespace:  System.CodeDom
Assembly:  System (in System.dll)

'Declaration
<SerializableAttribute> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class CodeMemberField _
	Inherits CodeTypeMember
'Usage
Dim instance As CodeMemberField

CodeMemberField can be used to represent the declaration for a field of a type.

The following example demonstrates use of a CodeMemberField to declare a field of type string named testStringField.

' Declares a type to contain a field and a constructor method. 
Dim type1 As New CodeTypeDeclaration("FieldTest")

' Declares a field of type String named testStringField. 
Dim field1 As New CodeMemberField("System.String", "testStringField")
type1.Members.Add(field1)

' Declares an empty type constructor. 
Dim constructor1 As New CodeConstructor()
constructor1.Attributes = MemberAttributes.Public
type1.Members.Add(constructor1)

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

' Public Class FieldTest 

'     Private TestStringField As String 

'     Public Sub New() 
'         MyBase.New() 
'     End Sub 

' End Class
' This example demonstrates declaring a public constant type member field. 
' When declaring a public constant type member field, you must set a particular 
' access and scope mask to the member attributes of the field in order for the 
' code generator to properly generate the field as a constant field. 
' Declares an integer field using a CodeMemberField 
Dim constPublicField As New CodeMemberField(GetType(Integer), "testConstPublicField")

' Resets the access and scope mask bit flags of the member attributes of the field 
' before setting the member attributes of the field to public and constant.
constPublicField.Attributes = constPublicField.Attributes And Not MemberAttributes.AccessMask And Not MemberAttributes.ScopeMask Or MemberAttributes.Public Or MemberAttributes.Const

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: