Macros.EmitMacroCode 方法

将代码行写到正在记录的宏。 此方法不应从宏内部使用。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

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

参数

  • Code
    类型:System.String
    必选。要添加给宏的代码行。

备注

可以使用 EmitMacroCode 来生成宏或将代码添加到现有的宏中。

如果环境未处于宏录制模式,则此方法会失败。 EmitMacroCode 只能从外接程序内部使用。

示例

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);
    }
}

.NET Framework 安全性

请参见

参考

Macros 接口

EnvDTE 命名空间

其他资源

使用宏自动执行重复性操作