本文整理汇总了C#中System.Management.Automation.PSCommand.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# PSCommand.Clear方法的具体用法?C# PSCommand.Clear怎么用?C# PSCommand.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.PSCommand
的用法示例。
在下文中一共展示了PSCommand.Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PreProcessDebuggerCommand
/// <summary>
/// Pre-processor for debugger commands.
/// Parses special debugger commands and converts to equivalent script for remote execution as needed.
/// </summary>
/// <param name="commands">PSCommand</param>
/// <param name="isDebuggerActive">True if debugger is active.</param>
/// <param name="isDebuggerRemote">True if active debugger is pushed and is a remote debugger.</param>
/// <param name="commandArgument">Command argument.</param>
/// <returns>PreProcessCommandResult type if preprocessing occurred.</returns>
private static PreProcessCommandResult PreProcessDebuggerCommand(
PSCommand commands,
bool isDebuggerActive,
bool isDebuggerRemote,
out DebuggerCommandArgument commandArgument)
{
commandArgument = new DebuggerCommandArgument();
PreProcessCommandResult result = PreProcessCommandResult.None;
if ((commands.Commands.Count == 0) || (commands.Commands[0].IsScript))
{
return result;
}
var command = commands.Commands[0];
string commandText = command.CommandText;
if (commandText.Equals(DebuggerUtils.GetDebuggerStopArgsFunctionName, StringComparison.OrdinalIgnoreCase))
{
//
// __Get-PSDebuggerStopArgs private virtual command.
// No input parameters.
// Returns DebuggerStopEventArgs object.
//
// Evaluate this command only if the debugger is activated.
if (!isDebuggerActive) { return PreProcessCommandResult.ValidNotProcessed; }
// Translate into debugger method call.
ScriptBlock scriptBlock = ScriptBlock.Create("$host.Runspace.Debugger.GetDebuggerStopArgs()");
scriptBlock.LanguageMode = PSLanguageMode.FullLanguage;
commands.Clear();
commands.AddCommand("Invoke-Command").AddParameter("ScriptBlock", scriptBlock).AddParameter("NoNewScope", true);
result = PreProcessCommandResult.GetDebuggerStopArgs;
}
else if (commandText.Equals(DebuggerUtils.SetDebuggerActionFunctionName, StringComparison.OrdinalIgnoreCase))
{
//
// __Set-PSDebuggerAction private virtual command.
// DebuggerResumeAction enum input parameter.
// Returns void.
//
// Evaluate this command only if the debugger is activated.
if (!isDebuggerActive) { return PreProcessCommandResult.ValidNotProcessed; }
if ((command.Parameters == null) || (command.Parameters.Count == 0) ||
(!command.Parameters[0].Name.Equals("ResumeAction", StringComparison.OrdinalIgnoreCase)))
{
throw new PSArgumentException("ResumeAction");
}
DebuggerResumeAction? resumeAction = null;
PSObject resumeObject = command.Parameters[0].Value as PSObject;
if (resumeObject != null)
{
try
{
resumeAction = (DebuggerResumeAction)resumeObject.BaseObject;
}
catch (InvalidCastException) { }
}
if (resumeAction == null)
{
throw new PSArgumentException("ResumeAction");
}
commandArgument.ResumeAction = resumeAction;
result = PreProcessCommandResult.SetDebuggerAction;
}
else if (commandText.Equals(DebuggerUtils.SetDebugModeFunctionName, StringComparison.OrdinalIgnoreCase))
{
//
// __Set-PSDebugMode private virtual command.
// DebugModes enum input parameter.
// Returns void.
//
if ((command.Parameters == null) || (command.Parameters.Count == 0) ||
(!command.Parameters[0].Name.Equals("Mode", StringComparison.OrdinalIgnoreCase)))
{
throw new PSArgumentException("Mode");
}
DebugModes? mode = null;
PSObject modeObject = command.Parameters[0].Value as PSObject;
if (modeObject != null)
{
try
{
//.........这里部分代码省略.........