Ejemplo n.º 1
0
        private CommandParameterCollection BindPositionalParameters(CommandParameterCollection parameters, CommandParameterSetInfo parameterSet)
        {
            var parametersWithoutName = from param in parameters
                                        where String.IsNullOrEmpty(param.Name)
                                        select param;

            if (parameterSet == null)
            {
                if (parametersWithoutName.Any())
                {
                    ThrowAmbiguousParameterSetException();
                }
                return(parameters);
            }
            var positionals = (from param in parameterSet.Parameters
                               where param.Position >= 0 && !_boundParameters.Contains(param.MemberInfo)
                               orderby param.Position ascending
                               select param).ToList();
            int i = 0;
            var parametersLeft = new CommandParameterCollection(parameters);

            foreach (var curParam in parametersWithoutName)
            {
                if (i >= positionals.Count)
                {
                    break; // can't bind it
                }

                BindParameter(positionals[i], curParam.Value, true);
                parametersLeft.Remove(curParam);
                i++;
            }
            return(parametersLeft);
        }
Ejemplo n.º 2
0
        private CommandParameterCollection BindNamedParameters(CommandParameterCollection parameters)
        {
            var namedParameters = from parameter in parameters
                                  where !String.IsNullOrEmpty(parameter.Name)
                                  select parameter;
            var parametersLeft = new CommandParameterCollection(parameters);

            foreach (var curParam in namedParameters)
            {
                string curName = curParam.Name;

                // try to get the parameter from any set. throws an error if the name is ambiguous or doesn't exist
                var paramInfo = _cmdletInfo.LookupParameter(curName);
                if (paramInfo != null)
                {
                    BindParameter(paramInfo, curParam.Value, true);
                    parametersLeft.Remove(curParam);
                }
            }
            return(parametersLeft);
        }
Ejemplo n.º 3
0
        private CommandParameterCollection BindPositionalParameters(CommandParameterCollection parameters, CommandParameterSetInfo parameterSet)
        {
            var parametersWithoutName = from param in parameters
                                        where String.IsNullOrEmpty(param.Name)
                                        select param;
            if (parameterSet == null)
            {
                if (parametersWithoutName.Any())
                {
                    ThrowAmbiguousParameterSetException();
                }
                return parameters;
            }
            var positionals = (from param in parameterSet.Parameters
                where param.Position >= 0 && !_boundParameters.Contains(param.MemberInfo)
                orderby param.Position ascending
                select param).ToList();
            int i = 0;
            var parametersLeft = new CommandParameterCollection(parameters);
            foreach (var curParam in parametersWithoutName)
            {
                if (i >= positionals.Count)
                {
                    break; // can't bind it
                }

                BindParameter(positionals[i], curParam.Value, true);
                parametersLeft.Remove(curParam);
                i++;
            }
            return parametersLeft;
        }
Ejemplo n.º 4
0
        private CommandParameterCollection BindNamedParameters(CommandParameterCollection parameters)
        {
            var namedParameters = from parameter in parameters
                                  where !String.IsNullOrEmpty(parameter.Name)
                                  select parameter;
            var parametersLeft = new CommandParameterCollection(parameters);
            foreach (var curParam in namedParameters)
            {
                string curName = curParam.Name;

                // try to get the parameter from any set. throws an error if the name is ambiguous or doesn't exist
                var paramInfo = _cmdletInfo.LookupParameter(curName);
                if (paramInfo != null) {
                    BindParameter(paramInfo, curParam.Value, true);
                    parametersLeft.Remove(curParam);
                }
            }
            return parametersLeft;
        }