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);
}
}
}