/// <summary> /// Extracts the data from the ParameterAttribute and creates the member data as necessary. /// </summary> /// <param name="parameterName"> /// The name of the parameter. /// </param> /// <param name="parameter"> /// The instance of the ParameterAttribute to extract the data from. /// </param> /// <exception cref="MetadataException"> /// If a parameter set name has already been declared on this parameter. /// </exception> private void ProcessParameterAttribute( string parameterName, ParameterAttribute parameter) { // If the parameter set name already exists on this parameter and the set name is the default parameter // set name, it is an error. if (ParameterSetData.ContainsKey(parameter.ParameterSetName)) { MetadataException e = new MetadataException( "ParameterDeclaredInParameterSetMultipleTimes", null, DiscoveryExceptions.ParameterDeclaredInParameterSetMultipleTimes, parameterName, parameter.ParameterSetName); throw e; } if (parameter.ValueFromPipeline || parameter.ValueFromPipelineByPropertyName) { IsPipelineParameterInSomeParameterSet = true; } if (parameter.Mandatory) { IsMandatoryInSomeParameterSet = true; } // Construct an instance of the parameter set specific data ParameterSetSpecificMetadata parameterSetSpecificData = new ParameterSetSpecificMetadata(parameter); ParameterSetData.Add(parameter.ParameterSetName, parameterSetSpecificData); }
/// <summary> /// Gets the parameter set data for this parameter for the specified parameter set. /// </summary> /// <param name="parameterSetFlag"> /// The parameter set to get the parameter set data for. /// </param> /// <returns> /// The parameter set specified data for the specified parameter set. /// </returns> internal ParameterSetSpecificMetadata GetParameterSetData(uint parameterSetFlag) { ParameterSetSpecificMetadata result = null; foreach (ParameterSetSpecificMetadata setData in ParameterSetData.Values) { // If the parameter is in all sets, then remember the data, but // try to find a more specific match if (setData.IsInAllSets) { result = setData; } else { if ((setData.ParameterSetFlag & parameterSetFlag) != 0) { result = setData; break; } } } return(result); }
private void SetParameterSetData(ParameterSetSpecificMetadata parameterMetadata) { IsMandatory = parameterMetadata.IsMandatory; Position = parameterMetadata.Position; ValueFromPipeline = parameterMetadata.valueFromPipeline; ValueFromPipelineByPropertyName = parameterMetadata.valueFromPipelineByPropertyName; ValueFromRemainingArguments = parameterMetadata.ValueFromRemainingArguments; HelpMessage = parameterMetadata.HelpMessage; }