本文整理汇总了C#中System.Management.Automation.PSVariable类的典型用法代码示例。如果您正苦于以下问题:C# PSVariable类的具体用法?C# PSVariable怎么用?C# PSVariable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PSVariable类属于System.Management.Automation命名空间,在下文中一共展示了PSVariable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ProcessRecord
protected override void ProcessRecord()
{
if (this.Force == 0)
{
PSVariable atScope = null;
if (string.IsNullOrEmpty(base.Scope))
{
atScope = base.SessionState.PSVariable.GetAtScope(this.name, "local");
}
else
{
atScope = base.SessionState.PSVariable.GetAtScope(this.name, base.Scope);
}
if (atScope != null)
{
SessionStateException replaceParentContainsErrorRecordException = new SessionStateException(this.name, SessionStateCategory.Variable, "VariableAlreadyExists", SessionStateStrings.VariableAlreadyExists, ErrorCategory.ResourceExists, new object[0]);
base.WriteError(new ErrorRecord(replaceParentContainsErrorRecordException.ErrorRecord, replaceParentContainsErrorRecordException));
return;
}
}
string newVariableAction = VariableCommandStrings.NewVariableAction;
string target = StringUtil.Format(VariableCommandStrings.NewVariableTarget, this.Name, this.Value);
if (base.ShouldProcess(target, newVariableAction))
{
PSVariable variable = new PSVariable(this.name, this._value, this.options);
if (this._visibility.HasValue)
{
variable.Visibility = this._visibility.Value;
}
if (this.description != null)
{
variable.Description = this.description;
}
try
{
if (string.IsNullOrEmpty(base.Scope))
{
base.SessionState.Internal.NewVariable(variable, (bool) this.Force);
}
else
{
base.SessionState.Internal.NewVariableAtScope(variable, base.Scope, (bool) this.Force);
}
}
catch (SessionStateException exception2)
{
base.WriteError(new ErrorRecord(exception2.ErrorRecord, exception2));
return;
}
catch (PSArgumentException exception3)
{
base.WriteError(new ErrorRecord(exception3.ErrorRecord, exception3));
return;
}
if (this.passThru)
{
base.WriteObject(variable);
}
}
}
开发者ID:nickchal,项目名称:pash,代码行数:60,代码来源:NewVariableCommand.cs
示例2: SetSessionStateItem
internal override void SetSessionStateItem(string name, object value, bool writeItem)
{
PSVariable variable = null;
if (value != null)
{
variable = value as PSVariable;
if (variable == null)
{
variable = new PSVariable(name, value);
}
else if (!string.Equals(name, variable.Name, StringComparison.OrdinalIgnoreCase))
{
variable = new PSVariable(name, variable.Value, variable.Options, variable.Attributes) {
Description = variable.Description
};
}
}
else
{
variable = new PSVariable(name, null);
}
PSVariable item = base.SessionState.Internal.SetVariable(variable, (bool) base.Force, base.Context.Origin) as PSVariable;
if (writeItem && (item != null))
{
base.WriteItemObject(item, item.Name, false);
}
}
开发者ID:nickchal,项目名称:pash,代码行数:27,代码来源:VariableProvider.cs
示例3: ProcessRecord
protected override void ProcessRecord()
{
// TODO: deal with Force
// TODO: deal with ShouldProcess
PSVariable variable = new PSVariable(Name, Value, Option);
if (Description != null)
{
variable.Description = Description;
}
//TODO: check if variable already exists and check if force has influence on behavior
//implement also an overloaded Get method in PSVariableIntrniscs that allow to pass a scope
try
{
//TODO: create a new overloaded method in PSVariableIntrinsics that allows to pass (bool)this.Force
SessionState.PSVariable.Set(variable);
}
catch (Exception ex)
{
WriteError(new ErrorRecord(ex, "", ErrorCategory.InvalidOperation, variable));
return;
}
if (PassThru.ToBool())
{
WriteObject(variable);
}
}
开发者ID:jagrem,项目名称:Pash,代码行数:27,代码来源:NewVariableCommand.cs
示例4: SetSessionStateItem
internal override void SetSessionStateItem(string name, object value, bool writeItem)
{
Path path = PathIntrinsics.RemoveDriveName(name);
name = path.TrimStartSlash();
PSVariable variable = null;
if (value != null)
{
variable = value as PSVariable;
if (variable == null)
{
variable = new PSVariable(name, value);
}
else if (String.Compare(name, variable.Name, true, System.Globalization.CultureInfo.CurrentCulture) != 0)
{
PSVariable var = new PSVariable(name, variable.Value, variable.Options, variable.Attributes);
var.Description = variable.Description;
variable = var;
}
}
else
{
variable = new PSVariable(name, null);
}
// TODO: can be Force'ed
SessionState.PSVariable.Set(variable);
PSVariable item = SessionState.PSVariable.Get(variable.Name);
if (writeItem && (item != null))
{
WriteItemObject(item, item.Name, false);
}
}
开发者ID:mauve,项目名称:Pash,代码行数:32,代码来源:VariableProvider.cs
示例5: AddSessionStateEntry
/// <summary>
/// Add an new SessionStateVariable entry to this session state object...
/// </summary>
/// <param name="entry">The entry to add</param>
internal void AddSessionStateEntry(SessionStateVariableEntry entry)
{
PSVariable v = new PSVariable(entry.Name, entry.Value,
entry.Options, entry.Attributes, entry.Description);
v.Visibility = entry.Visibility;
this.SetVariableAtScope(v, "global", true, CommandOrigin.Internal);
}
开发者ID:40a,项目名称:PowerShell,代码行数:11,代码来源:SessionStateVariableAPIs.cs
示例6: SetSessionStateItem
internal override void SetSessionStateItem(Path name, object value, bool writeItem)
{
PSVariable variable = null;
if (value != null)
{
variable = value as PSVariable;
if (variable == null)
{
variable = new PSVariable(name, value);
}
else if (String.Compare(name, variable.Name, true, System.Globalization.CultureInfo.CurrentCulture) != 0)
{
PSVariable var = new PSVariable(name, variable.Value, variable.Options, variable.Attributes);
var.Description = variable.Description;
variable = var;
}
}
else
{
variable = new PSVariable(name, null);
}
// TODO: can be Force'ed
PSVariable item = base.SessionState.SessionStateGlobal.SetVariable(variable) as PSVariable;
if (writeItem && (item != null))
{
WriteItemObject(item, item.Name, false);
}
}
开发者ID:b333z,项目名称:Pash,代码行数:28,代码来源:VariableProvider.cs
示例7: Set__variable
public static void Set__variable(this PSVariableProperty source, PSVariable value)
{
if (source == null)
throw new ArgumentNullException("source");
FieldSetterDelegate__variable.Set(source, value);
}
开发者ID:urasandesu,项目名称:Pontine,代码行数:7,代码来源:PSVariablePropertyMixin.cs
示例8: ProcessRecord
protected override void ProcessRecord()
{
// TODO: deal with scope
// TODO: deal with Force
// TODO: deal with ShouldProcess
PSVariable variable = new PSVariable(Name, Value, Option);
if (Description != null)
{
variable.Description = Description;
}
try
{
SessionState.SessionStateGlobal.NewVariable(variable, (bool)this.Force);
}
catch (Exception ex)
{
WriteError(new ErrorRecord(ex, "", ErrorCategory.InvalidOperation, variable));
return;
}
if (PassThru.ToBool())
{
WriteObject(variable);
}
}
开发者ID:JamesTryand,项目名称:Pash2,代码行数:25,代码来源:NewVariableCommand.cs
示例9: PSVariableProperty
public PSVariableProperty(PSVariable variable) : base((variable != null) ? variable.Name : null, null)
{
if (variable == null)
{
throw PSTraceSource.NewArgumentException("variable");
}
this._variable = variable;
}
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:PSVariableProperty.cs
示例10: CheckVariableCanBeChanged
protected internal void CheckVariableCanBeChanged(PSVariable variable, bool force)
{
if ((variable.ItemOptions.HasFlag(ScopedItemOptions.ReadOnly) && !force) ||
variable.ItemOptions.HasFlag(ScopedItemOptions.Constant))
{
throw SessionStateUnauthorizedAccessException.CreateVariableNotWritableError(variable);
}
}
开发者ID:Pash-Project,项目名称:Pash,代码行数:8,代码来源:VariableCommandBase.cs
示例11: CheckVariableCanBeRemoved
private void CheckVariableCanBeRemoved(PSVariable variable)
{
if ((variable.ItemOptions.HasFlag(ScopedItemOptions.ReadOnly) && !Force) ||
variable.ItemOptions.HasFlag(ScopedItemOptions.Constant))
{
throw SessionStateUnauthorizedAccessException.CreateVariableNotRemovableError(variable);
}
}
开发者ID:Pash-Project,项目名称:Pash,代码行数:8,代码来源:RemoveVariableCommand.cs
示例12: Remove
public void Remove(PSVariable variable)
{
//no scope specified when passing an object: we only care about the local scope
if (variable == null)
{
throw new ArgumentNullException("The variable is null.");
}
//add the local scope specifier to make sure we don't screw up with other variables
Remove("local:" + variable.Name);
}
开发者ID:prateek,项目名称:Pash,代码行数:10,代码来源:PSVariableIntrinsics.cs
示例13: ClearValue
private PSVariable ClearValue(PSVariable matchingVariable)
{
PSVariable variable = matchingVariable;
if (base.Scope != null)
{
matchingVariable.Value = null;
return variable;
}
base.SessionState.PSVariable.Set(matchingVariable.Name, null);
return base.SessionState.PSVariable.Get(matchingVariable.Name);
}
开发者ID:nickchal,项目名称:pash,代码行数:11,代码来源:ClearVariableCommand.cs
示例14: TryGetLocalVariable
internal bool TryGetLocalVariable(string name, bool fromNewOrSet, out PSVariable result)
{
int index;
name = VariableAnalysis.GetUnaliasedVariableName(name);
if (_nameToIndexMap.TryGetValue(name, out index) && (fromNewOrSet || IsValueSet(index)))
{
result = new LocalVariable(name, this, index);
return true;
}
result = null;
return false;
}
开发者ID:40a,项目名称:PowerShell,代码行数:12,代码来源:MutableTuple.cs
示例15: History
internal History(System.Management.Automation.ExecutionContext context)
{
Collection<Attribute> attributes = new Collection<Attribute> {
new ValidateRangeAttribute(1, 0x7fff)
};
PSVariable variable = new PSVariable("MaximumHistoryCount", 0x1000, ScopedItemOptions.None, attributes) {
Description = SessionStateStrings.MaxHistoryCountDescription
};
context.EngineSessionState.SetVariable(variable, false, CommandOrigin.Internal);
this._capacity = 0x1000;
this._buffer = new HistoryInfo[this._capacity];
}
开发者ID:nickchal,项目名称:pash,代码行数:12,代码来源:History.cs
示例16: 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
示例17: Set
public void Set(PSVariable variable)
{
if (variable == null)
{
throw new ArgumentNullException("The variable is null.");
}
var original = _scope.GetLocal(variable.Name);
if (original == null)
{
_scope.SetLocal(variable, true);
return;
}
original.Value = variable.Value;
original.Description = variable.Description;
original.Options = variable.Options;
_scope.SetLocal(original, true);
}
开发者ID:prateek,项目名称:Pash,代码行数:17,代码来源:PSVariableIntrinsics.cs
示例18: BindParameter
internal override void BindParameter(string name, object value)
{
if ((value == AutomationNull.Value) || (value == UnboundParameter.Value))
{
value = null;
}
VariablePath variablePath = new VariablePath(name, VariablePathFlags.Variable);
if (((this.LocalScope == null) || !variablePath.IsAnyLocal()) || !this.LocalScope.TrySetLocalParameterValue(variablePath.UnqualifiedPath, this.CopyMutableValues(value)))
{
RuntimeDefinedParameter parameter;
PSVariable newValue = new PSVariable(variablePath.UnqualifiedPath, value, variablePath.IsPrivate ? ScopedItemOptions.Private : ScopedItemOptions.None);
base.Context.EngineSessionState.SetVariable(variablePath, newValue, false, CommandOrigin.Internal);
if (this.Script.RuntimeDefinedParameters.TryGetValue(name, out parameter))
{
newValue.AddParameterAttributesNoChecks(parameter.Attributes);
}
}
}
开发者ID:nickchal,项目名称:pash,代码行数:18,代码来源:ScriptParameterBinder.cs
示例19: AddServiceConnection
/// <summary> A SessionState extension method that adds a service connection. </summary>
/// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null. </exception>
/// <param name="sessionState"> . </param>
/// <param name="connectionName"> The connection Name. </param>
/// <param name="connection"> The connection. </param>
/// <returns> A St2ClientConnection. </returns>
public static St2ClientConnection AddServiceConnection(this SessionState sessionState,
string connectionName, St2ClientConnection connection)
{
if (sessionState == null)
throw new ArgumentNullException("sessionState");
if (connection == null)
throw new ArgumentNullException("connection");
if (string.IsNullOrEmpty(connectionName))
throw new ArgumentNullException("connectionName");
Dictionary<string, St2ClientConnection> connections;
PSVariable connectionsVariable = sessionState.PSVariable.Get(VariableNames.ServiceSessions);
if (connectionsVariable == null)
{
connectionsVariable = new PSVariable(
VariableNames.ServiceSessions, connections = new Dictionary<string, St2ClientConnection>(),
ScopedItemOptions.AllScope
);
sessionState.PSVariable.Set(connectionsVariable);
}
else
{
connections = (Dictionary<string, St2ClientConnection>)connectionsVariable.Value;
if (connections == null)
{
connectionsVariable.Value = connections = new Dictionary<string, St2ClientConnection>();
sessionState.PSVariable.Set(connectionsVariable);
}
}
if (!connections.ContainsKey(connectionName))
connections.Add(connectionName, connection);
else
connections[connectionName] = connection;
if (string.IsNullOrEmpty(_defaultComputeServiceConnectionName) || connections.Count().Equals(1))
_defaultComputeServiceConnectionName = connectionName;
return connection;
}
开发者ID:tonybaloney,项目名称:St2Client,代码行数:48,代码来源:SessionStateExtensions.cs
示例20: CreateError
static SessionStateUnauthorizedAccessException CreateError(
PSVariable variable,
string message,
string errorId)
{
var ex = new SessionStateUnauthorizedAccessException(
message,
variable.Name,
SessionStateCategory.Variable);
var error = new ErrorRecord(
new ParentContainsErrorRecordException(ex),
errorId,
ErrorCategory.WriteError,
variable.Name);
ex.ErrorRecord = error;
ex.Source = typeof(PSVariable).Namespace;
return ex;
}
开发者ID:Pash-Project,项目名称:Pash,代码行数:21,代码来源:SessionStateUnauthorizedAccessException.cs
注:本文中的System.Management.Automation.PSVariable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论