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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。