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


C# ScriptBlock.InvokeUsingCmdlet方法代码示例

本文整理汇总了C#中System.Management.Automation.ScriptBlock.InvokeUsingCmdlet方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptBlock.InvokeUsingCmdlet方法的具体用法?C# ScriptBlock.InvokeUsingCmdlet怎么用?C# ScriptBlock.InvokeUsingCmdlet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.ScriptBlock的用法示例。


在下文中一共展示了ScriptBlock.InvokeUsingCmdlet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvokeScript

 private Collection<PSObject> InvokeScript(ScriptBlock sb, bool useNewScope, PipelineResultTypes writeToPipeline, IList input, params object[] args)
 {
     object obj2;
     if (this._cmdlet != null)
     {
         this._cmdlet.ThrowIfStopping();
     }
     Cmdlet contextCmdlet = null;
     ScriptBlock.ErrorHandlingBehavior writeToExternalErrorPipe = ScriptBlock.ErrorHandlingBehavior.WriteToExternalErrorPipe;
     if ((writeToPipeline & PipelineResultTypes.Output) == PipelineResultTypes.Output)
     {
         contextCmdlet = this._cmdlet;
         writeToPipeline &= ~PipelineResultTypes.Output;
     }
     if ((writeToPipeline & PipelineResultTypes.Error) == PipelineResultTypes.Error)
     {
         writeToExternalErrorPipe = ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe;
         writeToPipeline &= ~PipelineResultTypes.Error;
     }
     if (writeToPipeline != PipelineResultTypes.None)
     {
         throw PSTraceSource.NewNotImplementedException();
     }
     if (contextCmdlet != null)
     {
         sb.InvokeUsingCmdlet(contextCmdlet, useNewScope, writeToExternalErrorPipe, AutomationNull.Value, input, AutomationNull.Value, args);
         obj2 = AutomationNull.Value;
     }
     else
     {
         obj2 = sb.DoInvokeReturnAsIs(useNewScope, writeToExternalErrorPipe, AutomationNull.Value, input, AutomationNull.Value, args);
     }
     if (obj2 == AutomationNull.Value)
     {
         return new Collection<PSObject>();
     }
     Collection<PSObject> collection = obj2 as Collection<PSObject>;
     if (collection == null)
     {
         collection = new Collection<PSObject>();
         IEnumerator enumerator = null;
         enumerator = LanguagePrimitives.GetEnumerator(obj2);
         if (enumerator != null)
         {
             while (enumerator.MoveNext())
             {
                 object current = enumerator.Current;
                 collection.Add(LanguagePrimitives.AsPSObjectOrNull(current));
             }
             return collection;
         }
         collection.Add(LanguagePrimitives.AsPSObjectOrNull(obj2));
     }
     return collection;
 }
开发者ID:nickchal,项目名称:pash,代码行数:55,代码来源:CommandInvocationIntrinsics.cs

示例2: InvokeScript

        private Collection<PSObject> InvokeScript(ScriptBlock sb, bool useNewScope,
            PipelineResultTypes writeToPipeline, IList input, params object[] args)
        {
            if (null != _cmdlet)
                _cmdlet.ThrowIfStopping();

            Cmdlet cmdletToUse = null;
            ScriptBlock.ErrorHandlingBehavior errorHandlingBehavior = ScriptBlock.ErrorHandlingBehavior.WriteToExternalErrorPipe;

            // Check if they want output
            if ((writeToPipeline & PipelineResultTypes.Output) == PipelineResultTypes.Output)
            {
                cmdletToUse = _cmdlet;
                writeToPipeline &= (~PipelineResultTypes.Output);
            }

            // Check if they want error
            if ((writeToPipeline & PipelineResultTypes.Error) == PipelineResultTypes.Error)
            {
                errorHandlingBehavior = ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe;
                writeToPipeline &= (~PipelineResultTypes.Error);
            }

            if (writeToPipeline != PipelineResultTypes.None)
            {
                // The only output types are Output and Error.
                throw PSTraceSource.NewNotImplementedException();
            }

            // If the cmdletToUse is not null, then the result of the evaluation will be
            // streamed out the output pipe of the cmdlet.
            object rawResult;
            if (cmdletToUse != null)
            {
                sb.InvokeUsingCmdlet(
                    contextCmdlet: cmdletToUse,
                    useLocalScope: useNewScope,
                    errorHandlingBehavior: errorHandlingBehavior,
                    dollarUnder: AutomationNull.Value,
                    input: input,
                    scriptThis: AutomationNull.Value,
                    args: args);
                rawResult = AutomationNull.Value;
            }
            else
            {
                rawResult = sb.DoInvokeReturnAsIs(
                    useLocalScope: useNewScope,
                    errorHandlingBehavior: errorHandlingBehavior,
                    dollarUnder: AutomationNull.Value,
                    input: input,
                    scriptThis: AutomationNull.Value,
                    args: args);
            }

            if (rawResult == AutomationNull.Value)
            {
                return new Collection<PSObject>();
            }

            // If the result is already a collection of PSObjects, just return it...
            Collection<PSObject> result = rawResult as Collection<PSObject>;
            if (result != null)
                return result;

            result = new Collection<PSObject>();

            IEnumerator list = null;
            list = LanguagePrimitives.GetEnumerator(rawResult);

            if (list != null)
            {
                while (list.MoveNext())
                {
                    object val = list.Current;

                    result.Add(LanguagePrimitives.AsPSObjectOrNull(val));
                }
            }
            else
            {
                result.Add(LanguagePrimitives.AsPSObjectOrNull(rawResult));
            }

            return result;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:86,代码来源:MshCmdlet.cs


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