CodeMemberField Clase

Definición

Representa una declaración para un campo de un tipo.

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
Herencia
CodeMemberField
Atributos

Ejemplos

En el ejemplo siguiente se muestra el uso de para CodeMemberField declarar un campo de tipo string denominado testStringField.

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

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

// Declares an empty type constructor.
CodeConstructor^ constructor1 = gcnew 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.
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 = gcnew CodeMemberField( int::typeid,"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 = (MemberAttributes)((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
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

Comentarios

CodeMemberField se puede usar para representar la declaración de un campo de un tipo.

Constructores

CodeMemberField()

Inicializa una nueva instancia de la clase CodeMemberField.

CodeMemberField(CodeTypeReference, String)

Inicializa una nueva instancia de la clase CodeMemberField con el tipo y el nombre de campo especificados.

CodeMemberField(String, String)

Inicializa una nueva instancia de la clase CodeMemberField con el tipo y el nombre de campo especificados.

CodeMemberField(Type, String)

Inicializa una nueva instancia de la clase CodeMemberField con el tipo y el nombre de campo especificados.

Propiedades

Attributes

Obtiene o establece los atributos del miembro.

(Heredado de CodeTypeMember)
Comments

Obtiene la colección de comentarios del miembro del tipo.

(Heredado de CodeTypeMember)
CustomAttributes

Obtiene o establece los atributos personalizados del miembro.

(Heredado de CodeTypeMember)
EndDirectives

Obtiene las directivas End para el miembro.

(Heredado de CodeTypeMember)
InitExpression

Obtiene o establece la expresión de inicialización para el campo.

LinePragma

Obtiene o establece la línea en la que se produce la instrucción del miembro del tipo.

(Heredado de CodeTypeMember)
Name

Obtiene o establece el nombre del miembro.

(Heredado de CodeTypeMember)
StartDirectives

Obtiene las directivas Start para el miembro.

(Heredado de CodeTypeMember)
Type

Obtiene o establece el tipo del campo.

UserData

Obtiene los datos definibles por el usuario para el objeto actual.

(Heredado de CodeObject)

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a