System.Management.Automation.CmdletInfo.GetParameterSetByName C# (CSharp) Method

GetParameterSetByName() private method

private GetParameterSetByName ( string strParamSetName ) : CommandParameterSetInfo
strParamSetName string
return CommandParameterSetInfo
        internal CommandParameterSetInfo GetParameterSetByName(string strParamSetName)
        {
            foreach (CommandParameterSetInfo paramSetInfo in ParameterSets)
            {
                if (string.Compare(strParamSetName, paramSetInfo.Name, true) == 0)
                    return paramSetInfo;
            }

            return null;
        }

Usage Example

Esempio n. 1
0
        private void CheckForActiveParameterSet()
        {
            // if we only have one parameter set, this is always the active one (e.g. AllParametersSets)
            var setCount = _cmdletInfo.ParameterSets.Count;

            if (setCount == 1)
            {
                if (_activeSet == null)
                {
                    _activeSet = _cmdletInfo.ParameterSets[0];
                }
                return;
            }
            // if we have two sets and one is AllParametersSets, then the other one is naturally the default
            else if (setCount == 2)
            {
                var firstSet  = _cmdletInfo.ParameterSets[0];
                var secondSet = _cmdletInfo.ParameterSets[1];
                if (firstSet.Name.Equals(ParameterAttribute.AllParameterSets))
                {
                    _activeSet = secondSet;
                    return;
                }
                else if (secondSet.Name.Equals(ParameterAttribute.AllParameterSets))
                {
                    _activeSet = firstSet;
                    return;
                }
            }
            // otherwise we have more than one parameter set with name
            // even if an activeSet was already chosen, make sure there ist at most one active set
            foreach (var param in _boundParameters)
            {
                string activeSetName;
                if (_cmdletInfo.UniqueSetParameters.TryGetValue(param.Name, out activeSetName))
                {
                    if (_activeSet != null && !_activeSet.Name.Equals(activeSetName))
                    {
                        throw new ParameterBindingException("The parameter set selection is ambiguous!",
                                                            "AmbiguousParameterSet");
                    }
                    _activeSet = _cmdletInfo.GetParameterSetByName(activeSetName);
                }
            }
        }