本文整理汇总了C#中System.Management.Automation.ScriptBlock.InvokeReturnAsIs方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptBlock.InvokeReturnAsIs方法的具体用法?C# ScriptBlock.InvokeReturnAsIs怎么用?C# ScriptBlock.InvokeReturnAsIs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.ScriptBlock
的用法示例。
在下文中一共展示了ScriptBlock.InvokeReturnAsIs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runSBEvent
private void runSBEvent(ScriptBlock sb,
AutomationElement src,
AutomationEventArgs e)
{
// inform the Wait-UIAEventRaised cmdlet
SaveEventInput(
src,
e,
e.EventId.ProgrammaticName,
true);
// try {
// CurrentData.LastEventSource = src; // as AutomationElement;
// CurrentData.LastEventArgs = e; // as AutomationEventArgs;
// CurrentData.LastEventType = e.EventId.ProgrammaticName;
// CurrentData.LastEventInfoAdded = true;
// }
// catch {
// //WriteVerbose(this, "failed to register an event in the collection");
// }
// 20120206 Collection<PSObject > psObjects = null;
try {
System.Management.Automation.Runspaces.Runspace.DefaultRunspace =
RunspaceFactory.CreateRunspace();
try {
System.Management.Automation.Runspaces.Runspace.DefaultRunspace.Open();
} catch (Exception e1) {
// 20130318
// ErrorRecord err =
// new ErrorRecord(e1,
// "ErrorOnOpeningRunspace",
// ErrorCategory.InvalidOperation,
// sb);
// err.ErrorDetails =
// new ErrorDetails(
// "Unable to run a scriptblock:\r\n" +
// sb.ToString());
// WriteError(this, err, false);
this.WriteError(
this,
"Unable to run a scriptblock:\r\n" +
sb.ToString() +
"." +
e1.Message,
"ErrorOnOpeningRunspace",
ErrorCategory.InvalidOperation,
// 20130318
//false);
true);
}
try {
System.Collections.Generic.List<object> inputParams =
new System.Collections.Generic.List<object>();
inputParams.Add(src);
inputParams.Add(e);
object[] inputParamsArray = inputParams.ToArray();
// psObjects =
sb.InvokeReturnAsIs(inputParamsArray);
// sb.Invoke(inputParamsArray);
} catch (Exception e2) {
// 20130318
// ErrorRecord err =
// new ErrorRecord(e2,
// "ErrorInOpenedRunspace",
// ErrorCategory.InvalidOperation,
// sb);
// err.ErrorDetails =
// new ErrorDetails("Unable to run a scriptblock");
// WriteError(this, err, true);
this.WriteError(
this,
"Unable to run a scriptblock." +
e2.Message,
"ErrorInOpenedRunspace",
ErrorCategory.InvalidOperation,
true);
}
// psObjects =
// sb.Invoke();
} catch (Exception eOuter) {
// 20130318
// ErrorRecord err =
// new ErrorRecord(eOuter,
// "ErrorInInvokingScriptBlock", //"ErrorinCreatingRunspace",
// ErrorCategory.InvalidOperation,
// System.Management.Automation.Runspaces.Runspace.DefaultRunspace);
// err.ErrorDetails =
// new ErrorDetails("Unable to issue the following command:\r\n" +
// "System.Management.Automation.Runspaces.Runspace.DefaultRunspace = RunspaceFactory.CreateRunspace();" +
// "\r\nException raised is\r\n" +
// eOuter.Message);
this.WriteError(
this,
"Unable to issue the following command:\r\n" +
"System.Management.Automation.Runspaces.Runspace.DefaultRunspace = RunspaceFactory.CreateRunspace();" +
"\r\nException raised is\r\n" +
//.........这里部分代码省略.........
示例2: Invoke
public object Invoke(ScriptBlock sb, params object[] args)
{
object obj2;
if (sb == null)
{
return null;
}
SessionStateInternal sessionStateInternal = sb.SessionStateInternal;
try
{
sb.SessionStateInternal = this._sessionState.Internal;
obj2 = sb.InvokeReturnAsIs(args);
}
finally
{
sb.SessionStateInternal = sessionStateInternal;
}
return obj2;
}
示例3: InvokeScriptReturnAsIs
/// <summary>
/// Invokes the handler-like script and returns the result as it is.
/// </summary>
/// <param name="script">The script block to invoke.</param>
/// <param name="args">Script arguments.</param>
internal static object InvokeScriptReturnAsIs(ScriptBlock script, params object[] args)
{
if (Runspace.DefaultRunspace == null)
Runspace.DefaultRunspace = Psf.Runspace;
return script.InvokeReturnAsIs(args);
}