CodeMemberField Třída

Definice

Představuje deklaraci pole typu.

public ref class CodeMemberField : System::CodeDom::CodeTypeMember
public class CodeMemberField : System.CodeDom.CodeTypeMember
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeMemberField : System.CodeDom.CodeTypeMember
type CodeMemberField = class
    inherit CodeTypeMember
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeMemberField = class
    inherit CodeTypeMember
Public Class CodeMemberField
Inherits CodeTypeMember
Dědičnost
CodeMemberField
Atributy

Příklady

Následující příklad ukazuje použití k CodeMemberField deklarování pole typu string s názvem testStringField.

// Declares a type to contain a field and a constructor method.
CodeTypeDeclaration type1 = new CodeTypeDeclaration("FieldTest");

// Declares a field of type String named testStringField.
CodeMemberField field1 = new CodeMemberField("System.String", "TestStringField");
type1.Members.Add( field1 );

// Declares an empty type constructor.
CodeConstructor constructor1 = new CodeConstructor();
constructor1.Attributes = MemberAttributes.Public;
type1.Members.Add( constructor1 );

// A C# code generator produces the following source code for the preceeding example code:

//    public class FieldTest
//    {
//      private string testStringField;
//
//        public FieldTest()
//        {
//        }
//    }
' 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
CodeMemberField constPublicField = new CodeMemberField(typeof(int), "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 & ~MemberAttributes.AccessMask & ~MemberAttributes.ScopeMask) | MemberAttributes.Public | MemberAttributes.Const;
' 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

Poznámky

CodeMemberField lze použít k reprezentaci deklarace pro pole typu.

Konstruktory

Name Description
CodeMemberField()

Inicializuje novou instanci CodeMemberField třídy.

CodeMemberField(CodeTypeReference, String)

Inicializuje novou instanci CodeMemberField třídy pomocí zadaného typu pole a názvu pole.

CodeMemberField(String, String)

Inicializuje novou instanci CodeMemberField třídy pomocí zadaného typu pole a názvu pole.

CodeMemberField(Type, String)

Inicializuje novou instanci CodeMemberField třídy pomocí zadaného typu pole a názvu pole.

Vlastnosti

Name Description
Attributes

Získá nebo nastaví atributy člena.

(Zděděno od CodeTypeMember)
Comments

Získá kolekci komentářů pro člena typu.

(Zděděno od CodeTypeMember)
CustomAttributes

Získá nebo nastaví vlastní atributy člena.

(Zděděno od CodeTypeMember)
EndDirectives

Získá koncové direktivy pro člena.

(Zděděno od CodeTypeMember)
InitExpression

Získá nebo nastaví inicializační výraz pro pole.

LinePragma

Získá nebo nastaví řádek, na kterém dojde k příkazu člen typu.

(Zděděno od CodeTypeMember)
Name

Získá nebo nastaví název člena.

(Zděděno od CodeTypeMember)
StartDirectives

Získá počáteční direktivy pro člena.

(Zděděno od CodeTypeMember)
Type

Získá nebo nastaví typ pole.

UserData

Získá uživatelem definovatelná data pro aktuální objekt.

(Zděděno od CodeObject)

Metody

Name Description
Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetType()

Získá Type aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro