CodeAttribute2.Target (Propiedad)

Establece u obtiene el destino del atributo de código.

Espacio de nombres:  EnvDTE80
Ensamblado:  EnvDTE80 (en EnvDTE80.dll)

Sintaxis

'Declaración
Property Target As String
string Target { get; set; }
property String^ Target {
    String^ get ();
    void set (String^ value);
}
abstract Target : string with get, set
function get Target () : String
function set Target (value : String)

Valor de propiedad

Tipo: System.String
Un valor de cadena que representa el destino del atributo de código.

Comentarios

[!NOTA]

Los valores de los elementos de modelo de código como clases, structs, funciones, atributos, delegados, etc., pueden ser no deterministas una vez realizados determinados tipos de modificaciones; esto significa que no se puede confiar en que sus valores se mantengan siempre igual.Para obtener más información, vea la sección Los valores de elementos de modelo de código pueden cambiar, en Detectar código utilizando el modelo de código (Visual Basic).

Ejemplos

El siguiente ejemplo crea un nuevo espacio de nombres y atributo en la clase actual y muestra algunas de las propiedades del atributo.

public void CreateClassAndAttrib(DTE2 applicationObject)
{
    // Before running, load or create a project.
    FileCodeModel2 fcm2 = GetFileCodeModel(applicationObject);
    CodeAttribute2 cmAttribute;
    CodeClass2 cmClass;
    String msg = null;

    if (fcm2 != null)
    {
        CodeNamespace cmNamespace;
        // Try to create a new namespace.
        try
        {
            cmNamespace = fcm2.AddNamespace("CMNamespace", -1);
            // If successful, create the other code elements.
            if (cmNamespace != null)
            {
                cmClass = (CodeClass2)cmNamespace.AddClass("ANewClass", 
                -1, null, null, vsCMAccess.vsCMAccessPrivate);
                cmAttribute = (CodeAttribute2)cmClass.AddAttribute
                ("NewAttribute", "AttributeValue", -1);
                msg += "Project Item Name: " + 
                cmAttribute.ProjectItem.Name + Environment.NewLine;
                msg += "Startpoint DisplayColumn: " + 
                cmAttribute.StartPoint.DisplayColumn + 
                Environment.NewLine;
                msg += "Target: " + cmAttribute.Target + 
                Environment.NewLine;
                msg += "Value: " + cmAttribute.Value + 
                Environment.NewLine;
                MessageBox.Show(msg);                       
            }
            else
            {
                MessageBox.Show("Cannot continue - no filecodemodel 
                available.");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("ERROR: " + ex);
        }
    }
}

public FileCodeModel2 GetFileCodeModel(DTE2 applicationObject)
{
    // Returns the FileCodeModel object of the active 
    // window.
    TextWindow txtWin = 
    (TextWindow)applicationObject.ActiveWindow.Object;
    FileCodeModel2 fcm2;
    if (txtWin != null)
    {
        try
        {
             fcm2 = (FileCodeModel2)txtWin.Parent.
             ProjectItem.FileCodeModel;
             return fcm2;
        }
        catch (Exception ex)
        {
             MessageBox.Show("ERROR: " + ex);
             return null;
        }
    }
    else
        return null;
}

Seguridad de .NET Framework

Vea también

Referencia

CodeAttribute2 Interfaz

EnvDTE80 (Espacio de nombres)

Otros recursos

Cómo: Compilar y ejecutar los ejemplos de código del modelo de objetos de automatización

Detectar código utilizando el modelo de código (Visual Basic)

Detectar código utilizando el modelo de código (Visual C#)