internal override void BindParameter(string name, object value) { if (value == AutomationNull.Value || value == UnboundParameter.Value) { value = (object)null; } PSVariable variable = new PSVariable(name, value); this.Context.EngineSessionState.SetVariable(variable, false, CommandOrigin.Internal); if (!this.script.RuntimeDefinedParameters.ContainsKey(name)) { return; } RuntimeDefinedParameter definedParameter = this.script.RuntimeDefinedParameters[name]; variable.AddParameterAttributesNoChecks(definedParameter.Attributes); }
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); } } }
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); } } }
/// <summary> /// Binds the parameters to local variables in the function scope. /// </summary> /// <param name="name"> /// The name of the parameter to bind the value to. /// </param> /// <param name="value"> /// The value to bind to the parameter. It should be assumed by /// derived classes that the proper type coercion has already taken /// place and that any prerequisite metadata has been satisfied. /// </param> /// <param name="parameterMetadata"></param> internal override void BindParameter(string name, object value, CompiledCommandParameter parameterMetadata) { if (value == AutomationNull.Value || value == UnboundParameter.Value) { value = null; } Diagnostics.Assert(name != null, "The caller should verify that name is not null"); var varPath = new VariablePath(name, VariablePathFlags.Variable); // If the parameter was allocated in the LocalsTuple, we can avoid creating a PSVariable, if (LocalScope != null && varPath.IsAnyLocal() && LocalScope.TrySetLocalParameterValue(varPath.UnqualifiedPath, CopyMutableValues(value))) { return; } // Otherwise we'll fall through and enter a new PSVariable in the current scope. This // is what normally happens when dotting (though the above may succeed if a parameter name // was an automatic variable like $PSBoundParameters. // First we need to make a variable instance and apply // any attributes from the script. PSVariable variable = new PSVariable(varPath.UnqualifiedPath, value, varPath.IsPrivate ? ScopedItemOptions.Private : ScopedItemOptions.None); Context.EngineSessionState.SetVariable(varPath, variable, false, CommandOrigin.Internal); RuntimeDefinedParameter runtimeDefinedParameter; if (Script.RuntimeDefinedParameters.TryGetValue(name, out runtimeDefinedParameter)) { // The attributes have already been checked and conversions run, so it is wrong // to do so again. variable.AddParameterAttributesNoChecks(runtimeDefinedParameter.Attributes); } }
/// <summary> /// Binds the parameters to local variables in the function scope /// </summary> /// <param name="name"> /// The name of the parameter to bind the value to. /// </param> /// <param name="value"> /// The value to bind to the parameter. It should be assumed by /// derived classes that the proper type coercion has already taken /// place and that any prerequisite metadata has been satisfied. /// </param> /// <param name="parameterMetadata"></param> internal override void BindParameter(string name, object value, CompiledCommandParameter parameterMetadata) { if (value == AutomationNull.Value || value == UnboundParameter.Value) { value = null; } Diagnostics.Assert(name != null, "The caller should verify that name is not null"); var varPath = new VariablePath(name, VariablePathFlags.Variable); // If the parameter was allocated in the LocalsTuple, we can avoid creating a PSVariable, if (LocalScope != null && varPath.IsAnyLocal() && LocalScope.TrySetLocalParameterValue(varPath.UnqualifiedPath, CopyMutableValues(value))) { return; } // Otherwise we'll fall through and enter a new PSVariable in the current scope. This // is what normally happens when dotting (though the above may succeed if a parameter name // was an automatic variable like $PSBoundParameters. // First we need to make a variable instance and apply // any attributes from the script. PSVariable variable = new PSVariable(varPath.UnqualifiedPath, value, varPath.IsPrivate ? ScopedItemOptions.Private : ScopedItemOptions.None); Context.EngineSessionState.SetVariable(varPath, variable, false, CommandOrigin.Internal); RuntimeDefinedParameter runtimeDefinedParameter; if (Script.RuntimeDefinedParameters.TryGetValue(name, out runtimeDefinedParameter)) { // The attributes have already been checked and conversions run, so it is wrong // to do so again. variable.AddParameterAttributesNoChecks(runtimeDefinedParameter.Attributes); } } // BindParameter