当前位置: 首页>>代码示例>>C#>>正文


C# PSCommand.Clear方法代码示例

本文整理汇总了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
                    {
//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:ServerRunspacePoolDriver.cs


注:本文中的System.Management.Automation.PSCommand.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。