CodeMemberField Class

 

Represents a declaration for a field of a type.

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

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeTypeMember
      System.CodeDom.CodeMemberField

<SerializableAttribute>
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)>
<ComVisibleAttribute(True)>
Public Class CodeMemberField
	Inherits CodeTypeMember

NameDescription
System_CAPS_pubmethodCodeMemberField()

Initializes a new instance of the CodeMemberField class.

System_CAPS_pubmethodCodeMemberField(CodeTypeReference, String)

Initializes a new instance of the CodeMemberField class using the specified field type and field name.

System_CAPS_pubmethodCodeMemberField(String, String)

Initializes a new instance of the CodeMemberField class using the specified field type and field name.

System_CAPS_pubmethodCodeMemberField(Type, String)

Initializes a new instance of the CodeMemberField class using the specified field type and field name.

NameDescription
System_CAPS_pubpropertyAttributes

Gets or sets the attributes of the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyComments

Gets the collection of comments for the type member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyCustomAttributes

Gets or sets the custom attributes of the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyEndDirectives

Gets the end directives for the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyInitExpression

Gets or sets the initialization expression for the field.

System_CAPS_pubpropertyLinePragma

Gets or sets the line on which the type member statement occurs.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyName

Gets or sets the name of the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyStartDirectives

Gets the start directives for the member.(Inherited from CodeTypeMember.)

System_CAPS_pubpropertyType

Gets or sets the type of the field.

System_CAPS_pubpropertyUserData

Gets the user-definable data for the current object.(Inherited from CodeObject.)

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

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

.NET Framework
Available since 1.1

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

Return to top
Show: