System.Management.Automation.CommandProcessor.BindArguments C# (CSharp) Method

BindArguments() private method

All abount Cmdlet parameters: http://msdn2.microsoft.com/en-us/library/ms714433(VS.85).aspx
private BindArguments ( System.Management.Automation.PSObject obj ) : void
obj System.Management.Automation.PSObject
return void
        internal override void BindArguments(PSObject obj)
        {
            if ((obj == null) && (Parameters.Count == 0))
                return;

            // TODO: bind the arguments to the parameters
            CommandParameterSetInfo paramSetInfo = _cmdletInfo.GetDefaultParameterSet();
            // TODO: refer to the Command._ParameterSetName for a param set name

            if (obj != null)
            {
                var valueFromPipelineParameter = paramSetInfo.Parameters.Where(paramInfo => paramInfo.ValueFromPipeline).SingleOrDefault();

                if (valueFromPipelineParameter != null)
                    BindArgument(valueFromPipelineParameter.Name, obj, valueFromPipelineParameter.ParameterType);
            }

            if (Parameters.Count > 0)
            {
                // bind by position location
                for (int i = 0; i < Parameters.Count; i++)
                {
                    CommandParameterInfo paramInfo = null;

                    CommandParameter parameter = Parameters[i];

                    if (string.IsNullOrEmpty(parameter.Name))
                    {
                        paramInfo = paramSetInfo.GetParameterByPosition(i);

                        if (paramInfo != null)
                        {
                            BindArgument(paramInfo.Name, parameter.Value, paramInfo.ParameterType);
                        }
                    }
                    else
                    {
                        paramInfo = paramSetInfo.GetParameterByName(parameter.Name);

                        if (paramInfo != null)
                        {
                            if (parameter.Value == null && paramInfo.ParameterType != typeof(SwitchParameter)
                                && i < Parameters.Count - 1 && Parameters[i + 1].Name == null)
                            {
                                BindArgument(paramInfo.Name, Parameters[i + 1].Value, paramInfo.ParameterType);
                                i++;
                            }
                            else
                                BindArgument(paramInfo.Name, parameter.Value, paramInfo.ParameterType);
                        }
                    }
                }
            }
        }

Usage Example

コード例 #1
0
ファイル: BindingTests.cs プロジェクト: b333z/Pash
        public void BindingAmbiguous()
        {
            CommandProcessor cmdProc = new CommandProcessor(info);
            TestParameterCommand cmdlet = new TestParameterCommand();
            cmdProc.Command = cmdlet;

            cmdProc.AddParameter("i", 10);

            Assert.Throws(typeof(ArgumentException), delegate() {
                cmdProc.BindArguments(null);
            });
        }
All Usage Examples Of System.Management.Automation.CommandProcessor::BindArguments