示例#1
0
        /// <summary>
        /// Constructs the parameter binder with the specified type metadata. The binder is only valid
        /// for a single instance of a bindable runtime-defined parameter collection and only for the duration of a command.
        /// </summary>
        /// 
        /// <param name="target">
        /// The target runtime-defined parameter collection that the parameter values will be bound to.
        /// </param>
        /// 
        /// <param name="command">
        /// An instance of the command so that attributes can access the context.
        /// </param>
        /// 
        /// <param name="commandLineParameters">
        /// The Command line parameter collection to update...
        /// </param>
        /// 
        internal RuntimeDefinedParameterBinder(
            RuntimeDefinedParameterDictionary target,
            InternalCommand command,
            CommandLineParameters commandLineParameters)
            : base(target, command.MyInvocation, command.Context, command)
        {
            // NTRAID#Windows Out Of Band Releases-927103-2006/01/25-JonN
            foreach (var pair in target)
            {
                string key = pair.Key;
                RuntimeDefinedParameter pp = pair.Value;
                string ppName = (null == pp) ? null : pp.Name;
                if (null == pp || key != ppName)
                {
                    ParameterBindingException bindingException =
                        new ParameterBindingException(
                            ErrorCategory.InvalidArgument,
                            command.MyInvocation,
                            null,
                            ppName,
                            null,
                            null,
                            ParameterBinderStrings.RuntimeDefinedParameterNameMismatch,
                            "RuntimeDefinedParameterNameMismatch",
                            key);

                    throw bindingException;
                }
            }
            this.CommandLineParameters = commandLineParameters;
        }
        /// <summary>
        /// Constructs the parameter binder with the specified type metadata. The binder is only valid
        /// for a single instance of a bindable runtime-defined parameter collection and only for the duration of a command.
        /// </summary>
        ///
        /// <param name="target">
        /// The target runtime-defined parameter collection that the parameter values will be bound to.
        /// </param>
        ///
        /// <param name="command">
        /// An instance of the command so that attributes can access the context.
        /// </param>
        ///
        /// <param name="commandLineParameters">
        /// The Command line parameter collection to update...
        /// </param>
        ///
        internal RuntimeDefinedParameterBinder(
            RuntimeDefinedParameterDictionary target,
            InternalCommand command,
            CommandLineParameters commandLineParameters)
            : base(target, command.MyInvocation, command.Context, command)
        {
            // NTRAID#Windows Out Of Band Releases-927103-2006/01/25-JonN
            foreach (var pair in target)
            {
                string key = pair.Key;
                RuntimeDefinedParameter pp = pair.Value;
                string ppName = (null == pp) ? null : pp.Name;
                if (null == pp || key != ppName)
                {
                    ParameterBindingException bindingException =
                        new ParameterBindingException(
                            ErrorCategory.InvalidArgument,
                            command.MyInvocation,
                            null,
                            ppName,
                            null,
                            null,
                            ParameterBinderStrings.RuntimeDefinedParameterNameMismatch,
                            "RuntimeDefinedParameterNameMismatch",
                            key);

                    throw bindingException;
                }
            }
            this.CommandLineParameters = commandLineParameters;
        }
 internal RuntimeDefinedParameterBinder(
     RuntimeDefinedParameterDictionary target,
     InternalCommand command,
     CommandLineParameters commandLineParameters)
     : base((object)target, command.MyInvocation, command.Context, command)
 {
     using (RuntimeDefinedParameterBinder.tracer.TraceConstructor((object)this))
     {
         foreach (string key in target.Keys)
         {
             RuntimeDefinedParameter definedParameter = target[key];
             string parameterName = definedParameter == null ? (string)null : definedParameter.Name;
             if (definedParameter == null || key != parameterName)
             {
                 ParameterBindingException bindingException = new ParameterBindingException(ErrorCategory.InvalidArgument, command.MyInvocation, (Token)null, parameterName, (Type)null, (Type)null, "ParameterBinderStrings", "RuntimeDefinedParameterNameMismatch", new object[1]
                 {
                     (object)key
                 });
                 RuntimeDefinedParameterBinder.tracer.TraceException((Exception)bindingException);
                 throw bindingException;
             }
         }
         this.CommandLineParameters = commandLineParameters;
     }
 }
示例#4
0
 /// <summary>
 /// Constructs the parameter binder with the specified type metadata. The binder is only valid
 /// for a single instance of a bindable object and only for the duration of a command.
 /// </summary>
 /// <param name="target">
 /// The target object that the parameter values will be bound to.
 /// </param>
 /// <param name="command">
 /// An instance of the command so that attributes can access the context.
 /// </param>
 /// <param name="commandLineParameters">
 /// The dictionary to use to record the parameters set by this object...
 /// </param>
 internal ReflectionParameterBinder(
     object target,
     Cmdlet command,
     CommandLineParameters commandLineParameters)
     : base(target, command.MyInvocation, command.Context, command)
 {
     this.CommandLineParameters = commandLineParameters;
 }
 /// <summary>
 /// Constructs the parameter binder with the specified type metadata. The binder is only valid
 /// for a single instance of a bindable object and only for the duration of a command.
 /// </summary>
 /// 
 /// <param name="target">
 /// The target object that the parameter values will be bound to.
 /// </param>
 /// 
 /// <param name="command">
 /// An instance of the command so that attributes can access the context.
 /// </param>
 /// 
 /// <param name="commandLineParameters">
 /// The dictionary to use to record the parameters set by this object...
 /// </param>
 /// 
 internal ReflectionParameterBinder(
     object target,
     Cmdlet command,
     CommandLineParameters commandLineParameters)
     : base(target, command.MyInvocation, command.Context, command)
 {
     this.CommandLineParameters = commandLineParameters;
 }
示例#6
0
 public void PrepareForBinding(SessionStateScope scope, CommandLineParameters commandLineParameters)
 {
     if (this._useLocalScope && (scope.LocalsTuple == null))
     {
         scope.LocalsTuple = this._localsTuple;
     }
     this._localsTuple.SetAutomaticVariable(AutomaticVariable.PSBoundParameters, commandLineParameters.GetValueToBindToPSBoundParameters(), base.Context);
     this._localsTuple.SetAutomaticVariable(AutomaticVariable.MyInvocation, base.MyInvocation, base.Context);
 }
示例#7
0
 internal ReflectionParameterBinder(
     object target,
     Cmdlet command,
     CommandLineParameters commandLineParameters)
     : base((object)LanguagePrimitives.AsPSObjectOrNull(target), command.MyInvocation, command.Context, (InternalCommand)command)
 {
     using (ReflectionParameterBinder.tracer.TraceConstructor((object)this))
         this.CommandLineParameters = commandLineParameters;
 }
 internal RuntimeDefinedParameterBinder(RuntimeDefinedParameterDictionary target, InternalCommand command, CommandLineParameters commandLineParameters) : base(target, command.MyInvocation, command.Context, command)
 {
     foreach (string str in target.Keys)
     {
         RuntimeDefinedParameter parameter = target[str];
         string parameterName = (parameter == null) ? null : parameter.Name;
         if ((parameter == null) || (str != parameterName))
         {
             ParameterBindingException exception = new ParameterBindingException(ErrorCategory.InvalidArgument, command.MyInvocation, null, parameterName, null, null, "ParameterBinderStrings", "RuntimeDefinedParameterNameMismatch", new object[] { str });
             throw exception;
         }
     }
     base.CommandLineParameters = commandLineParameters;
 }
 internal RuntimeDefinedParameterBinder(RuntimeDefinedParameterDictionary target, InternalCommand command, CommandLineParameters commandLineParameters) : base(target, command.MyInvocation, command.Context, command)
 {
     foreach (string str in target.Keys)
     {
         RuntimeDefinedParameter parameter = target[str];
         string parameterName = (parameter == null) ? null : parameter.Name;
         if ((parameter == null) || (str != parameterName))
         {
             ParameterBindingException exception = new ParameterBindingException(ErrorCategory.InvalidArgument, command.MyInvocation, null, parameterName, null, null, "ParameterBinderStrings", "RuntimeDefinedParameterNameMismatch", new object[] { str });
             throw exception;
         }
     }
     base.CommandLineParameters = commandLineParameters;
 }
示例#10
0
 public void PrepareForBinding(SessionStateScope scope, CommandLineParameters commandLineParameters)
 {
     if (_useLocalScope && scope.LocalsTuple == null)
     {
         scope.LocalsTuple = _localsTuple;
     }
     _localsTuple.SetAutomaticVariable(AutomaticVariable.PSBoundParameters,
                                       commandLineParameters.GetValueToBindToPSBoundParameters(), this.Context);
     _localsTuple.SetAutomaticVariable(AutomaticVariable.MyInvocation, MyInvocation, this.Context);
 }
示例#11
0
        internal static object[] BindArgumentsForScriptblockInvoke(
            RuntimeDefinedParameter[] parameters,
            object[] args,
            ExecutionContext context,
            bool dotting,
            Dictionary<string, PSVariable> backupWhenDotting,
            MutableTuple locals)
        {
            var boundParameters = new CommandLineParameters();

            if (parameters.Length == 0)
            {
                return args;
            }

            for (int i = 0; i < parameters.Length; i++)
            {
                var parameter = parameters[i];
                object valueToBind;
                bool wasDefaulted = false;
                if (i >= args.Length)
                {
                    valueToBind = parameter.Value;
                    if (valueToBind is Compiler.DefaultValueExpressionWrapper)
                    {
                        // We pass in a null SessionStateInternal because the current scope is already set correctly.
                        valueToBind = ((Compiler.DefaultValueExpressionWrapper)valueToBind).GetValue(context, null);
                    }
                    wasDefaulted = true;
                }
                else
                {
                    valueToBind = args[i];
                }

                bool valueSet = false;
                if (dotting && backupWhenDotting != null)
                {
                    backupWhenDotting[parameter.Name] = context.EngineSessionState.GetVariableAtScope(parameter.Name, "local");
                }
                else
                {
                    valueSet = locals.TrySetParameter(parameter.Name, valueToBind);
                }

                if (!valueSet)
                {
                    var variable = new PSVariable(parameter.Name, valueToBind, ScopedItemOptions.None, parameter.Attributes);
                    context.EngineSessionState.SetVariable(variable, false, CommandOrigin.Internal);
                }

                if (!wasDefaulted)
                {
                    boundParameters.Add(parameter.Name, valueToBind);
                    boundParameters.MarkAsBoundPositionally(parameter.Name);
                }
            }

            locals.SetAutomaticVariable(AutomaticVariable.PSBoundParameters, boundParameters.GetValueToBindToPSBoundParameters(), context);

            var leftOverArgs = args.Length - parameters.Length;
            if (leftOverArgs <= 0)
            {
                return Utils.EmptyArray<object>();
            }

            object[] result = new object[leftOverArgs];
            Array.Copy(args, parameters.Length, result, 0, result.Length);
            return result;
        }
示例#12
0
 internal static object[] BindArgumentsForScripblockInvoke(RuntimeDefinedParameter[] parameters, object[] args, ExecutionContext context, bool dotting, Dictionary<string, PSVariable> backupWhenDotting, MutableTuple locals)
 {
     object value;
     CommandLineParameters commandLineParameter = new CommandLineParameters();
     if ((int)parameters.Length != 0)
     {
         for (int i = 0; i < (int)parameters.Length; i++)
         {
             RuntimeDefinedParameter variableAtScope = parameters[i];
             bool flag = false;
             if (i < (int)args.Length)
             {
                 value = args[i];
             }
             else
             {
                 value = variableAtScope.Value;
                 if (value as Compiler.DefaultValueExpressionWrapper != null)
                 {
                     value = ((Compiler.DefaultValueExpressionWrapper)value).GetValue(context, null, null);
                 }
                 flag = true;
             }
             bool flag1 = false;
             if (!dotting || backupWhenDotting == null)
             {
                 flag1 = locals.TrySetParameter(variableAtScope.Name, value);
             }
             else
             {
                 backupWhenDotting[variableAtScope.Name] = context.EngineSessionState.GetVariableAtScope(variableAtScope.Name, "local");
             }
             if (!flag1)
             {
                 PSVariable pSVariable = new PSVariable(variableAtScope.Name, value, ScopedItemOptions.None, variableAtScope.Attributes);
                 context.EngineSessionState.SetVariable(pSVariable, false, CommandOrigin.Internal);
             }
             if (!flag)
             {
                 commandLineParameter.Add(variableAtScope.Name, value);
                 commandLineParameter.MarkAsBoundPositionally(variableAtScope.Name);
             }
         }
         locals.SetAutomaticVariable(AutomaticVariable.PSBoundParameters, commandLineParameter.GetValueToBindToPSBoundParameters(), context);
         int length = (int)args.Length - (int)parameters.Length;
         if (length > 0)
         {
             object[] objArray = new object[length];
             Array.Copy(args, (int)parameters.Length, objArray, 0, (int)objArray.Length);
             return objArray;
         }
         else
         {
             return ScriptBlock.EmptyArray;
         }
     }
     else
     {
         return args;
     }
 }