Condividi tramite


Metodo Macros.EmitMacroCode

Scrive la riga di codice durante la registrazione della macro. Il metodo non è utilizzabile dall'interno di una macro.

Spazio dei nomi:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Sintassi

'Dichiarazione
Sub EmitMacroCode ( _
    Code As String _
)
void EmitMacroCode(
    string Code
)
void EmitMacroCode(
    String^ Code
)
abstract EmitMacroCode : 
        Code:string -> unit 
function EmitMacroCode(
    Code : String
)

Parametri

  • Code
    Tipo: System.String
    Obbligatorio.La riga di codice da aggiungere alla macro.

Note

È possibile utilizzare il metodo EmitMacroCode per compilare macro o per aggiungere codice alle macro esistenti.

Questo metodo non viene eseguito correttamente se l'ambiente non è in modalità di registrazione macro. Il metodo EmitMacroCode deve essere utilizzato solo dall'interno di componenti aggiuntivi.

Esempi

public void CodeExample(DTE2 dte, AddIn addin)
{
    // INSTRUCTIONS: Run this code, open a solution, start
    // recording a macro, then connect the add-in containing this code.
    try
    {
        Macros mac = dte.Macros;
        if (mac.IsRecording)
        {
            mac.Pause();
            if (!mac.IsRecording)
                mac.Resume();
            mac.EmitMacroCode("rem Code added by the EmitMacroCode method");
            // Demonstrate these two properties return the same reference.
            bool test = mac.DTE.Equals(mac.Parent);
            if (test) MessageBox.Show("The DTE and Parent property refer to the same object.");
            else MessageBox.Show("The DTE and Parent property do not refer to the same object.");
        }
        else MessageBox.Show("Start a macro recording session and reconnect addin");
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Macros Interfaccia

Spazio dei nomi EnvDTE

Altre risorse

Automazione di operazioni ripetitive tramite macro