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


C# ScriptBlock.Invoke方法代码示例

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


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

示例1: Invoke

      /// <summary>
      /// Invoke a <see cref="ScriptBlock"/>, binding it to the module, if possible.
      /// </summary>
      /// <param name="sb">The <see cref="ScriptBlock"/></param>
      /// <param name="variables">Variables to set before invoking</param>
      /// <param name="args">Arguments to the <see cref="ScriptBlock"/></param>
      /// <returns>A collection of <see cref="PSObject"/></returns>
      internal static ICollection<PSObject> Invoke(ScriptBlock sb, PSVariable[] variables, params object[] args)
      {
         if (variables == null)
            throw new ArgumentNullException("variables");

         foreach (var v in variables) SetScriptVariable(v);

         if (_module != null)
         {
            sb = _module.NewBoundScriptBlock(sb);
         }

         return sb.Invoke(args);
      }
开发者ID:ForNeVeR,项目名称:PoshConsole,代码行数:21,代码来源:Invoker.cs

示例2: SetKeyHandler

        /// <summary>
        /// Helper function for the Set-PSReadlineKeyHandler cmdlet.
        /// </summary>
        public static void SetKeyHandler(string[] key, ScriptBlock scriptBlock, string briefDescription, string longDescription)
        {
            Action<ConsoleKeyInfo?, object> handler = (k, arg) =>
            {
                try
                {
                    scriptBlock.Invoke(k, arg);
                }
                catch (Exception e)
                {
                    throw new CustomHandlerException(e);
                }
            };

            _singleton.SetKeyHandlerInternal(key, handler, briefDescription, longDescription, scriptBlock);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:19,代码来源:Options.cs

示例3: runSBActionWithParams

        private void runSBActionWithParams(
            ScriptBlock sb,
            object[] parameters)
        {
            Collection<PSObject> psObjects = null;
            try {

                this.WriteVerbose(
                    this,
                    "select whether a scriptblock has parameters or doesn't");

                if (null == parameters || 0 == parameters.Length) {

                    this.WriteVerbose(
                        this,
                        "without parameters");

                    psObjects =
                        sb.Invoke();

                } else {

                    this.WriteVerbose(
                        this,
                        "with parameters");

                    psObjects =
                        sb.Invoke(parameters);

                }

                this.WriteVerbose(
                    this,
                    "scriptblock has been fired successfully");

            } catch (Exception eOuter) {

                // 20130318
            //                ErrorRecord err =
            //                    new ErrorRecord(eOuter,
            //                                    "ErrorInInvokingScriptBlock",
            //                                    ErrorCategory.InvalidOperation,
            //                                    System.Management.Automation.Runspaces.Runspace.DefaultRunspace);
            //                err.ErrorDetails =
            //                    new ErrorDetails(
            //                        "Unable to issue the following command:\r\n" +
            //                        sb.ToString() +
            //                        "\r\nThe exception raised is\r\n" +
            //                        eOuter.Message);
            //                                     //"System.Management.Automation.Runspaces.Runspace.DefaultRunspace = RunspaceFactory.CreateRunspace();");
            //                WriteError(err);

                // 20130606
            //                this.WriteVerbose(
            //                    this,
            //                    eOuter.InnerException.Message);

                this.WriteError(
                    this,
                    "Unable to issue the following command:\r\n" +
                    sb.ToString() +
                    "\r\nThe exception raised is\r\n" +
                    eOuter.Message,
                    "ErrorInInvokingScriptBlock",
                    ErrorCategory.InvalidOperation,
                    // 20130318
                    //false);
                    true);

            }
        }
开发者ID:krukovskiy,项目名称:STUPS,代码行数:71,代码来源:PSCmdletBase.cs

示例4: runSBAction

        private void runSBAction(ScriptBlock sb, 
                                 AutomationElement src,
                                 AutomationEventArgs e)
        {
            Collection<PSObject> psObjects = null;
            try {
                psObjects =
                    sb.Invoke();
            // int counter = 0;
            // foreach (PSObject pso in psObjects) {
            //  //if pso.
            // counter++;
            // WriteVerbose("result " + counter.ToString() + ":");
            // WriteVerbose(pso.ToString());
            //  //WriteObject(pso.TypeNames
            // foreach ( string typeName in pso.TypeNames) {
            // WriteVerbose(typeName);
            // }
            // }
            } catch (Exception eOuter) {
                // 20130318
            //                ErrorRecord err =
            //                    new ErrorRecord(eOuter,
            //                                    "ErrorInInvokingScriptBlock",
            //                                    ErrorCategory.InvalidOperation,
            //                                    System.Management.Automation.Runspaces.Runspace.DefaultRunspace);
            //                err.ErrorDetails =
            //                    new ErrorDetails(
            //                        "Unable to issue the following command:\r\n" +
            //                        sb.ToString() +
            //                        "\r\nThe exception raised is\r\n" +
            //                        eOuter.Message);
            //                                     //"System.Management.Automation.Runspaces.Runspace.DefaultRunspace = RunspaceFactory.CreateRunspace();");
            //                WriteError(err);

                this.WriteError(
                    this,
                    "Unable to issue the following command:\r\n" +
                    sb.ToString() +
                    "\r\nThe exception raised is\r\n" +
                    eOuter.Message,
                    "ErrorInInvokingScriptBlock",
                    ErrorCategory.InvalidOperation,
                    // 20130318
                    //false);
                    true);
            }
        }
开发者ID:krukovskiy,项目名称:STUPS,代码行数:48,代码来源:PSCmdletBase.cs

示例5: InvokeScript

        /// <summary>
        /// Invokes the script block and returns the result collection.
        /// </summary>
        /// <param name="script">The script block to invoke.</param>
        /// <param name="args">Script arguments.</param>
        internal static Collection<PSObject> InvokeScript(ScriptBlock script, params object[] args)
        {
            if (Runspace.DefaultRunspace == null)
                Runspace.DefaultRunspace = Psf.Runspace;

            return script.Invoke(args);
        }
开发者ID:AndBicScadMedia,项目名称:farnet,代码行数:12,代码来源:A.cs

示例6: RunSbActionWithParams

 void RunSbActionWithParams(ScriptBlock sb, object[] parameters)
 {
     Collection<PSObject> psObjects = null;
     try {
         Trace.TraceInformation("runSBActionWithParams.1");
         if (null == parameters || 0 == parameters.Length)
             psObjects = sb.Invoke();
         else
             psObjects = sb.Invoke(parameters);
         Trace.TraceInformation("runSBActionWithParams.2");
     } catch (Exception eOuter) {
         // TODO: AOP
         Trace.TraceError("runSBActionWithParams(ScriptBlock sb, object[] parameters)");
         Trace.TraceError(eOuter.Message);
         throw new Exception(
             "Unable to issue the following command:\r\n" +
             sb +
             "\r\nThe exception raised is\r\n" +
             eOuter.Message);
     }
 }
开发者ID:apetrovskiy,项目名称:STUPS,代码行数:21,代码来源:PowerShellTaskRunner.cs

示例7: SetKeyHandler

 /// <summary>
 /// Helper function for the Set-PSReadlineKeyHandler cmdlet.
 /// </summary>
 public static void SetKeyHandler(string[] key, ScriptBlock scriptBlock, string briefDescription, string longDescription)
 {
     Action<ConsoleKeyInfo?, object> handler =
         (k, arg) => scriptBlock.Invoke(k, arg);
     _singleton.SetKeyHandlerInternal(key, handler, briefDescription, longDescription, scriptBlock);
 }
开发者ID:kenrachynski,项目名称:PSReadLine,代码行数:9,代码来源:Options.cs

示例8: ArbitraryFilter

        private static bool ArbitraryFilter(NtThread thread, ScriptBlock filter)
        {
            try
            {
                ICollection<PSObject> os = filter.Invoke(thread);
                if (os.Count == 1)
                {
                    return (bool)os.First().BaseObject;
                }
            }
            catch
            {
            }

            return false;
        }
开发者ID:CaledoniaProject,项目名称:sandbox-attacksurface-analysis-tools,代码行数:16,代码来源:NtThreadCmdlets.cs

示例9: InvokeScriptBlock

 /// <summary>
 /// Invokes the specified script block.
 /// </summary>
 internal virtual Collection<PSObject> InvokeScriptBlock(
     ScriptBlock scriptBlock
 )
 {
     return scriptBlock.Invoke(null);
 }
开发者ID:joshedler,项目名称:pstest,代码行数:9,代码来源:InvokeTestCmdlet.cs


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