本文整理汇总了C#中System.Management.Automation.PSVariable类的典型用法代码示例。如果您正苦于以下问题:C# PSVariable类的具体用法?C# PSVariable怎么用?C# PSVariable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PSVariable类属于System.Management.Automation命名空间,在下文中一共展示了PSVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例9: PSVariableProperty
public PSVariableProperty(PSVariable variable) : base((variable != null) ? variable.Name : null, null)
{
if (variable == null)
{
throw PSTraceSource.NewArgumentException("variable");
}
this._variable = variable;
}
示例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);
}
}
示例11: CheckVariableCanBeRemoved
private void CheckVariableCanBeRemoved(PSVariable variable)
{
if ((variable.ItemOptions.HasFlag(ScopedItemOptions.ReadOnly) && !Force) ||
variable.ItemOptions.HasFlag(ScopedItemOptions.Constant))
{
throw SessionStateUnauthorizedAccessException.CreateVariableNotRemovableError(variable);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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];
}