本文整理汇总了C#中System.Management.Automation.ScriptBlock.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptBlock.Clone方法的具体用法?C# ScriptBlock.Clone怎么用?C# ScriptBlock.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.ScriptBlock
的用法示例。
在下文中一共展示了ScriptBlock.Clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
internal static ScriptBlock Create(Parser parser, string fileName, string fileContents)
{
var scriptBlock = TryGetCachedScriptBlock(fileName, fileContents);
if (scriptBlock != null)
{
return scriptBlock;
}
ParseError[] errors;
var ast = parser.Parse(fileName, fileContents, null, out errors, ParseMode.Default);
if (errors.Length != 0)
{
throw new ParseException(errors);
}
var result = new ScriptBlock(ast, isFilter: false);
CacheScriptBlock(result, fileName, fileContents);
// The value returned will potentially be bound to a session state. We don't want
// the cached script block to end up being bound to any session state, so clone
// the return value to ensure the cached value has no session state.
return result.Clone();
}
示例2: NewBoundScriptBlock
internal ScriptBlock NewBoundScriptBlock(ScriptBlock scriptBlockToBind, ExecutionContext context)
{
ScriptBlock block;
if ((this._sessionState == null) || (context == null))
{
throw PSTraceSource.NewInvalidOperationException("Modules", "InvalidOperationOnBinaryModule", new object[0]);
}
lock (context.EngineSessionState)
{
SessionStateInternal engineSessionState = context.EngineSessionState;
try
{
context.EngineSessionState = this._sessionState.Internal;
block = scriptBlockToBind.Clone(true);
block.SessionState = this._sessionState;
}
finally
{
context.EngineSessionState = engineSessionState;
}
}
return block;
}
示例3: PSModuleInfo
public PSModuleInfo(ScriptBlock scriptBlock)
{
this._name = string.Empty;
this._path = string.Empty;
this._description = string.Empty;
this._version = new System.Version(0, 0);
this._detectedFunctionExports = new List<string>();
this._detectedWorkflowExports = new List<string>();
this._detectedCmdletExports = new List<string>();
this._compiledExports = new List<CmdletInfo>();
this._fileList = new List<string>();
this._moduleList = new Collection<object>();
this._nestedModules = new List<PSModuleInfo>();
this._scripts = new List<string>();
this._requiredAssemblies = new Collection<string>();
this._requiredModules = new List<PSModuleInfo>();
this._requiredModulesSpecification = new List<ModuleSpecification>();
this._detectedAliasExports = new Dictionary<string, string>();
this._exportedFormatFiles = new ReadOnlyCollection<string>(new List<string>());
this._exportedTypeFiles = new ReadOnlyCollection<string>(new List<string>());
if (scriptBlock == null)
{
throw PSTraceSource.NewArgumentException("scriptBlock");
}
ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS();
if (executionContextFromTLS == null)
{
throw new InvalidOperationException("PSModuleInfo");
}
SetDefaultDynamicNameAndPath(this);
this._sessionState = new System.Management.Automation.SessionState(executionContextFromTLS, true, true);
this._sessionState.Internal.Module = this;
SessionStateInternal engineSessionState = executionContextFromTLS.EngineSessionState;
try
{
executionContextFromTLS.EngineSessionState = this._sessionState.Internal;
executionContextFromTLS.SetVariable(SpecialVariables.PSScriptRootVarPath, this._path);
scriptBlock = scriptBlock.Clone(true);
scriptBlock.SessionState = this._sessionState;
Pipe outputPipe = new Pipe {
NullPipe = true
};
scriptBlock.InvokeWithPipe(false, ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, AutomationNull.Value, AutomationNull.Value, AutomationNull.Value, outputPipe, null, new object[0]);
}
finally
{
executionContextFromTLS.EngineSessionState = engineSessionState;
}
}
示例4: Create
internal static ScriptBlock Create(Parser parser, string fileName, string fileContents)
{
ParseError[] parseErrorArray = null;
ScriptBlock scriptBlock = ScriptBlock.TryGetCachedScriptBlock(fileName, fileContents);
if (scriptBlock == null)
{
ScriptBlockAst scriptBlockAst = parser.Parse(fileName, fileContents, null, out parseErrorArray);
if ((int)parseErrorArray.Length == 0)
{
ScriptBlock scriptBlock1 = new ScriptBlock(scriptBlockAst, false);
ScriptBlock.CacheScriptBlock(scriptBlock1, fileName, fileContents);
return scriptBlock1.Clone(false);
}
else
{
throw new ParseException(parseErrorArray);
}
}
else
{
return scriptBlock;
}
}