CodeMemberField Classe

Definizione

Rappresenta una dichiarazione per un campo di un tipo.

public ref 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
[<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
Ereditarietà
CodeMemberField
Attributi

Esempio

Nell'esempio seguente viene illustrato l'uso di un CodeMemberField oggetto per dichiarare un campo di tipo string denominato 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

Commenti

CodeMemberField può essere utilizzato per rappresentare la dichiarazione per un campo di un tipo.

Costruttori

Nome Descrizione
CodeMemberField()

Inizializza una nuova istanza della classe CodeMemberField.

CodeMemberField(CodeTypeReference, String)

Inizializza una nuova istanza della CodeMemberField classe utilizzando il tipo di campo e il nome del campo specificati.

CodeMemberField(String, String)

Inizializza una nuova istanza della CodeMemberField classe utilizzando il tipo di campo e il nome del campo specificati.

CodeMemberField(Type, String)

Inizializza una nuova istanza della CodeMemberField classe utilizzando il tipo di campo e il nome del campo specificati.

Proprietà

Nome Descrizione
Attributes

Ottiene o imposta gli attributi del membro.

(Ereditato da CodeTypeMember)
Comments

Ottiene la raccolta di commenti per il membro del tipo.

(Ereditato da CodeTypeMember)
CustomAttributes

Ottiene o imposta gli attributi personalizzati del membro.

(Ereditato da CodeTypeMember)
EndDirectives

Ottiene le direttive end per il membro.

(Ereditato da CodeTypeMember)
InitExpression

Ottiene o imposta l'espressione di inizializzazione per il campo.

LinePragma

Ottiene o imposta la riga in cui si verifica l'istruzione membro del tipo.

(Ereditato da CodeTypeMember)
Name

Ottiene o imposta il nome del membro.

(Ereditato da CodeTypeMember)
StartDirectives

Ottiene le direttive start per il membro.

(Ereditato da CodeTypeMember)
Type

Ottiene o imposta il tipo del campo.

UserData

Ottiene i dati definibili dall'utente per l'oggetto corrente.

(Ereditato da CodeObject)

Metodi

Nome Descrizione
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a