/********************************************************************++ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System.Collections.Generic; using System.Collections.ObjectModel; namespace System.Management.Automation { /// /// Provides information about a cmdlet parameter for a particular parameter set. /// public class CommandParameterInfo { #region ctor /// /// Constructs the parameter info using the specified aliases, attributes, and /// parameter set metadata /// /// /// /// The parameter metadata to retrieve the parameter information from. /// /// /// /// The parameter set flag to get the parameter information from. /// /// /// /// If is null. /// /// internal CommandParameterInfo( CompiledCommandParameter parameter, uint parameterSetFlag) { if (parameter == null) { throw PSTraceSource.NewArgumentNullException("parameter"); } Name = parameter.Name; ParameterType = parameter.Type; IsDynamic = parameter.IsDynamic; Aliases = new ReadOnlyCollection(parameter.Aliases); SetAttributes(parameter.CompiledAttributes); SetParameterSetData(parameter.GetParameterSetData(parameterSetFlag)); } #endregion ctor #region public members /// /// Gets the name of the parameter. /// public string Name { get; } = String.Empty; /// /// Gets the type of the parameter. /// public Type ParameterType { get; } /// /// Gets whether or not the parameter is a dynamic parameter. /// /// /// /// True if the parameter is dynamic, or false otherwise. /// public bool IsMandatory { get; private set; } /// /// Gets whether or not the parameter is mandatory. /// /// /// /// True if the parameter is mandatory, or false otherwise. /// public bool IsDynamic { get; } /// /// Gets the position in which the parameter can be specified on the command line /// if not named. If the returned value is int.MinValue then the parameter must be named. /// public int Position { get; private set; } = int.MinValue; /// /// Gets whether the parameter can take values from the incoming pipeline object. /// public bool ValueFromPipeline { get; private set; } /// /// Gets whether the parameter can take values from a property inn the incoming /// pipeline object with the same name as the parameter. /// public bool ValueFromPipelineByPropertyName { get; private set; } /// /// Gets whether the parameter will take any argument that isn't bound to another parameter. /// public bool ValueFromRemainingArguments { get; private set; } /// /// Gets the help message for this parameter. /// public string HelpMessage { get; private set; } = String.Empty; /// /// Gets the aliases by which this parameter can be referenced. /// public ReadOnlyCollection Aliases { get; } /// /// Gets the attributes that are specified on the parameter. /// public ReadOnlyCollection Attributes { get; private set; } #endregion public members #region private members private void SetAttributes(IList attributeMetadata) { Diagnostics.Assert( attributeMetadata != null, "The compiled attribute collection should never be null"); Collection processedAttributes = new Collection(); foreach (var attribute in attributeMetadata) { processedAttributes.Add(attribute); } Attributes = new ReadOnlyCollection(processedAttributes); } private void SetParameterSetData(ParameterSetSpecificMetadata parameterMetadata) { IsMandatory = parameterMetadata.IsMandatory; Position = parameterMetadata.Position; ValueFromPipeline = parameterMetadata.valueFromPipeline; ValueFromPipelineByPropertyName = parameterMetadata.valueFromPipelineByPropertyName; ValueFromRemainingArguments = parameterMetadata.ValueFromRemainingArguments; HelpMessage = parameterMetadata.HelpMessage; } #endregion private members } // class CommandParameterInfo } // namespace System.Management.Automation