Exemple #1
0
        /// <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);
        }
 private static void AddNewPosition(SortedDictionary<int, Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter>> result, int positionInParameterSet, MergedCompiledCommandParameter parameter, ParameterSetSpecificMetadata parameterSetData)
 {
     if (result.ContainsKey(positionInParameterSet))
     {
         Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter> positionalCommandParameters = result[positionInParameterSet];
         if (ContainsPositionalParameterInSet(positionalCommandParameters, parameter, parameterSetData.ParameterSetFlag))
         {
             throw PSTraceSource.NewInvalidOperationException();
         }
         if (positionalCommandParameters.ContainsKey(parameter))
         {
             positionalCommandParameters[parameter].ParameterSetData.Add(parameterSetData);
         }
         else
         {
             PositionalCommandParameter parameter2 = new PositionalCommandParameter(parameter);
             parameter2.ParameterSetData.Add(parameterSetData);
             positionalCommandParameters.Add(parameter, parameter2);
         }
     }
     else
     {
         Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter> dictionary2 = new Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter>();
         PositionalCommandParameter parameter3 = new PositionalCommandParameter(parameter) {
             ParameterSetData = { parameterSetData }
         };
         dictionary2.Add(parameter, parameter3);
         result.Add(positionInParameterSet, dictionary2);
     }
 }
Exemple #3
0
        internal uint GenerateParameterSetMappingFromMetadata(string defaultParameterSetName)
        {
            this.parameterSetMap.Clear();
            this.nextAvailableParameterSetIndex = 0U;
            uint num1 = 0;

            if (!string.IsNullOrEmpty(defaultParameterSetName))
            {
                this._defaultParameterSetName = defaultParameterSetName;
                num1 = (uint)(1 << this.AddParameterSetToMap(defaultParameterSetName, (CompiledCommandParameter)null));
            }
            foreach (MergedCompiledCommandParameter commandParameter in this.BindableParameters.Values)
            {
                uint num2 = 0;
                foreach (string key in commandParameter.Parameter.ParameterSetData.Keys)
                {
                    if (string.Equals(key, "__AllParameterSets", StringComparison.OrdinalIgnoreCase))
                    {
                        ParameterSetSpecificMetadata specificMetadata = commandParameter.Parameter.ParameterSetData[key];
                        specificMetadata.ParameterSetFlag      = 0U;
                        specificMetadata.IsInAllSets           = true;
                        commandParameter.Parameter.IsInAllSets = true;
                    }
                    else
                    {
                        uint num3 = (uint)(1 << this.AddParameterSetToMap(key, commandParameter.Parameter));
                        num2 |= num3;
                        commandParameter.Parameter.ParameterSetData[key].ParameterSetFlag = num3;
                    }
                }
                commandParameter.Parameter.ParameterSetFlags = num2;
            }
            return(num1);
        }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
 private void SetParameterSetData(ParameterSetSpecificMetadata parameterMetadata)
 {
     IsMandatory       = parameterMetadata.IsMandatory;
     Position          = parameterMetadata.Position;
     ValueFromPipeline = parameterMetadata.valueFromPipeline;
     ValueFromPipelineByPropertyName = parameterMetadata.valueFromPipelineByPropertyName;
     ValueFromRemainingArguments     = parameterMetadata.ValueFromRemainingArguments;
     HelpMessage = parameterMetadata.HelpMessage;
 }
 private void SetParameterSetData(ParameterSetSpecificMetadata parameterMetadata)
 {
     this.isMandatory = parameterMetadata.IsMandatory;
     this.position = parameterMetadata.Position;
     this.valueFromPipeline = parameterMetadata.valueFromPipeline;
     this.valueFromPipelineByPropertyName = parameterMetadata.valueFromPipelineByPropertyName;
     this.valueFromRemainingArguments = parameterMetadata.ValueFromRemainingArguments;
     this.helpMessage = parameterMetadata.HelpMessage;
 }
 internal void Initialize(ParameterSetSpecificMetadata psMD)
 {
     this.isMandatory       = psMD.IsMandatory;
     this.position          = psMD.Position;
     this.valueFromPipeline = psMD.ValueFromPipeline;
     this.valueFromPipelineByPropertyName = psMD.ValueFromPipelineByPropertyName;
     this.valueFromRemainingArguments     = psMD.ValueFromRemainingArguments;
     this.helpMessage           = psMD.HelpMessage;
     this.helpMessageBaseName   = psMD.HelpMessageBaseName;
     this.helpMessageResourceId = psMD.HelpMessageResourceId;
 }
Exemple #8
0
 private void SetParameterSetData(ParameterSetSpecificMetadata parameterMetadata)
 {
     using (CommandParameterInfo.tracer.TraceMethod())
     {
         this.isMandatory       = parameterMetadata.IsMandatory;
         this.position          = parameterMetadata.Position;
         this.valueFromPipeline = parameterMetadata.valueFromPipeline;
         this.valueFromPipelineByPropertyName = parameterMetadata.valueFromPipelineByPropertyName;
         this.valueFromRemainingArguments     = parameterMetadata.ValueFromRemainingArguments;
         this.helpMessage = parameterMetadata.HelpMessage;
     }
 }
Exemple #9
0
        internal ParameterSetSpecificMetadata GetParameterSetData(int parameterSetFlag)
        {
            ParameterSetSpecificMetadata metadata = null;

            foreach (ParameterSetSpecificMetadata metadata2 in this.ParameterSetData.Values)
            {
                if (metadata2.IsInAllSets)
                {
                    metadata = metadata2;
                }
                else if ((metadata2.ParameterSetFlag & parameterSetFlag) != 0)
                {
                    return(metadata2);
                }
            }
            return(metadata);
        }
Exemple #10
0
        private void ProcessParameterAttribute(string parameterName, ParameterAttribute parameter)
        {
            if (this._parameterSetData.ContainsKey(parameter.ParameterSetName))
            {
                System.Management.Automation.MetadataException exception = new System.Management.Automation.MetadataException("ParameterDeclaredInParameterSetMultipleTimes", null, DiscoveryExceptions.ParameterDeclaredInParameterSetMultipleTimes, new object[] { parameterName, parameter.ParameterSetName });
                throw exception;
            }
            if (parameter.ValueFromPipeline || parameter.ValueFromPipelineByPropertyName)
            {
                this._isPipelineParameterInSomeParameterSet = true;
            }
            if (parameter.Mandatory)
            {
                this._isMandatoryInSomeParameterSet = true;
            }
            ParameterSetSpecificMetadata metadata = new ParameterSetSpecificMetadata(parameter);

            this._parameterSetData.Add(parameter.ParameterSetName, metadata);
        }
Exemple #11
0
 internal void Initialize(CompiledCommandParameter compiledParameterMD)
 {
     this.name          = compiledParameterMD.Name;
     this.parameterType = compiledParameterMD.Type;
     this.isDynamic     = compiledParameterMD.IsDynamic;
     this.parameterSets = new Dictionary <string, ParameterSetMetadata>(StringComparer.OrdinalIgnoreCase);
     foreach (string str in compiledParameterMD.ParameterSetData.Keys)
     {
         ParameterSetSpecificMetadata psMD = compiledParameterMD.ParameterSetData[str];
         this.parameterSets.Add(str, new ParameterSetMetadata(psMD));
     }
     this.aliases = new Collection <string>();
     foreach (string str2 in compiledParameterMD.Aliases)
     {
         this.aliases.Add(str2);
     }
     this.attributes = new Collection <Attribute>();
     foreach (Attribute attribute in compiledParameterMD.CompiledAttributes)
     {
         this.attributes.Add(attribute);
     }
 }
        private void BuildSyntaxForParameterSet(XmlElement command, XmlElement syntax, MergedCommandParameterMetadata parameterMetadata, int i)
        {
            XmlElement newChild = this.doc.CreateElement("command:syntaxItem", commandURI);
            XmlElement element2 = this.doc.CreateElement("maml:name", mamlURI);
            XmlText    text     = this.doc.CreateTextNode(this.commandName);

            newChild.AppendChild(element2).AppendChild(text);
            foreach (MergedCompiledCommandParameter parameter in parameterMetadata.GetParametersInParameterSet(((int)1) << i))
            {
                if (parameter.BinderAssociation != ParameterBinderAssociation.CommonParameters)
                {
                    CompiledCommandParameter     parameter2       = parameter.Parameter;
                    ParameterSetSpecificMetadata parameterSetData = parameter2.GetParameterSetData(((int)1) << i);
                    string parameterDescription = this.GetParameterDescription(parameter2.Name);
                    bool   supportsWildcards    = (from attribute in parameter2.CompiledAttributes
                                                   where attribute is SupportsWildcardsAttribute
                                                   select attribute).Any <System.Attribute>();
                    XmlElement element3 = this.BuildXmlForParameter(parameter2.Name, parameterSetData.IsMandatory, parameterSetData.ValueFromPipeline, parameterSetData.ValueFromPipelineByPropertyName, parameterSetData.IsPositional ? ((1 + parameterSetData.Position)).ToString(CultureInfo.InvariantCulture) : "named", parameter2.Type, parameterDescription, supportsWildcards, "", true);
                    newChild.AppendChild(element3);
                }
            }
            command.AppendChild(syntax).AppendChild(newChild);
        }
Exemple #13
0
        internal int GenerateParameterSetMappingFromMetadata(string defaultParameterSetName)
        {
            this.parameterSetMap.Clear();
            this.nextAvailableParameterSetIndex = 0;
            int num = 0;

            if (!string.IsNullOrEmpty(defaultParameterSetName))
            {
                this._defaultParameterSetName = defaultParameterSetName;
                int num2 = this.AddParameterSetToMap(defaultParameterSetName);
                num = ((int)1) << num2;
            }
            foreach (MergedCompiledCommandParameter parameter in this.BindableParameters.Values)
            {
                int num3 = 0;
                foreach (KeyValuePair <string, ParameterSetSpecificMetadata> pair in parameter.Parameter.ParameterSetData)
                {
                    string key = pair.Key;
                    ParameterSetSpecificMetadata metadata = pair.Value;
                    if (string.Equals(key, "__AllParameterSets", StringComparison.OrdinalIgnoreCase))
                    {
                        metadata.ParameterSetFlag       = 0;
                        metadata.IsInAllSets            = true;
                        parameter.Parameter.IsInAllSets = true;
                    }
                    else
                    {
                        int num4 = this.AddParameterSetToMap(key);
                        int num5 = ((int)1) << num4;
                        num3 |= num5;
                        metadata.ParameterSetFlag = num5;
                    }
                }
                parameter.Parameter.ParameterSetFlags = num3;
            }
            return(num);
        }
Exemple #14
0
        private void BuildSyntaxForParameterSet(
            XmlElement command,
            XmlElement syntax,
            MergedCommandParameterMetadata parameterMetadata,
            int i)
        {
            XmlElement element1 = this.doc.CreateElement("command:syntaxItem", HelpCommentsParser.commandURI);
            XmlElement element2 = this.doc.CreateElement("maml:name", HelpCommentsParser.mamlURI);
            XmlText    textNode = this.doc.CreateTextNode(this.commandName);

            element1.AppendChild((XmlNode)element2).AppendChild((XmlNode)textNode);
            foreach (MergedCompiledCommandParameter parametersInParameter in parameterMetadata.GetParametersInParameterSet((uint)(1 << i)))
            {
                if (parametersInParameter.BinderAssociation != ParameterBinderAssociation.CommonParameters)
                {
                    CompiledCommandParameter     parameter        = parametersInParameter.Parameter;
                    ParameterSetSpecificMetadata parameterSetData = parameter.GetParameterSetData((uint)(1 << i));
                    string     parameterDescription = this.GetParameterDescription(parameter.Name);
                    XmlElement xmlElement           = this.BuildXmlForParameter(parameter.Name, parameterSetData.IsMandatory, parameterSetData.ValueFromPipeline, parameterSetData.ValueFromPipelineByPropertyName, parameterSetData.IsPositional ? (1 + parameterSetData.Position).ToString((IFormatProvider)CultureInfo.InvariantCulture) : "named", parameter.Type, parameterDescription, true);
                    element1.AppendChild((XmlNode)xmlElement);
                }
            }
            command.AppendChild((XmlNode)syntax).AppendChild((XmlNode)element1);
        }
Exemple #15
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="psMD"></param>
 internal ParameterSetMetadata(ParameterSetSpecificMetadata psMD)
 {
     Dbg.Assert(null != psMD, "ParameterSetSpecificMetadata cannot be null");
     Initialize(psMD);
 }
Exemple #16
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="psMD"></param>
 internal void Initialize(ParameterSetSpecificMetadata psMD)
 {
     _isMandatory = psMD.IsMandatory;
     _position = psMD.Position;
     _valueFromPipeline = psMD.ValueFromPipeline;
     _valueFromPipelineByPropertyName = psMD.ValueFromPipelineByPropertyName;
     _valueFromRemainingArguments = psMD.ValueFromRemainingArguments;
     _helpMessage = psMD.HelpMessage;
     _helpMessageBaseName = psMD.HelpMessageBaseName;
     _helpMessageResourceId = psMD.HelpMessageResourceId;
 }
        private uint NewParameterSetPromptingData(
            Dictionary<uint, ParameterSetPromptingData> promptingData,
            MergedCompiledCommandParameter parameter,
            ParameterSetSpecificMetadata parameterSetMetadata,
            uint defaultParameterSet,
            bool pipelineInputExpected)
        {
            uint parameterMandatorySets = 0;
            uint parameterSetFlag = parameterSetMetadata.ParameterSetFlag;
            if (parameterSetFlag == 0)
            {
                parameterSetFlag = uint.MaxValue;
            }
            bool isDefaultSet = (defaultParameterSet != 0) && ((defaultParameterSet & parameterSetFlag) != 0);

            bool isMandatory = false;
            if (parameterSetMetadata.IsMandatory)
            {
                parameterMandatorySets |= parameterSetFlag;
                isMandatory = true;
            }

            bool isPipelineable = false;
            if (pipelineInputExpected)
            {
                if (parameterSetMetadata.ValueFromPipeline || parameterSetMetadata.ValueFromPipelineByPropertyName)
                {
                    isPipelineable = true;
                }
            }

            if (isMandatory)
            {
                ParameterSetPromptingData promptingDataForSet;
                if (!promptingData.TryGetValue(parameterSetFlag, out promptingDataForSet))
                {
                    promptingDataForSet = new ParameterSetPromptingData(parameterSetFlag, isDefaultSet);
                    promptingData.Add(parameterSetFlag, promptingDataForSet);
                }

                if (isPipelineable)
                {
                    promptingDataForSet.PipelineableMandatoryParameters[parameter] = parameterSetMetadata;

                    if (parameterSetMetadata.ValueFromPipeline)
                    {
                        promptingDataForSet.PipelineableMandatoryByValueParameters[parameter] = parameterSetMetadata;
                    }

                    if (parameterSetMetadata.ValueFromPipelineByPropertyName)
                    {
                        promptingDataForSet.PipelineableMandatoryByPropertyNameParameters[parameter] = parameterSetMetadata;
                    }
                }
                else
                {
                    promptingDataForSet.NonpipelineableMandatoryParameters[parameter] = parameterSetMetadata;
                }
            }

            return parameterMandatorySets;
        }
Exemple #18
0
 internal ParameterSetMetadata(ParameterSetSpecificMetadata psMD)
 {
     this.Initialize(psMD);
 }
 private void ProcessParameterAttribute(string parameterName, ParameterAttribute parameter)
 {
     if (this._parameterSetData.ContainsKey(parameter.ParameterSetName))
     {
         System.Management.Automation.MetadataException exception = new System.Management.Automation.MetadataException("ParameterDeclaredInParameterSetMultipleTimes", null, DiscoveryExceptions.ParameterDeclaredInParameterSetMultipleTimes, new object[] { parameterName, parameter.ParameterSetName });
         throw exception;
     }
     if (parameter.ValueFromPipeline || parameter.ValueFromPipelineByPropertyName)
     {
         this._isPipelineParameterInSomeParameterSet = true;
     }
     if (parameter.Mandatory)
     {
         this._isMandatoryInSomeParameterSet = true;
     }
     ParameterSetSpecificMetadata metadata = new ParameterSetSpecificMetadata(parameter);
     this._parameterSetData.Add(parameter.ParameterSetName, metadata);
 }
 internal ParameterSetMetadata(ParameterSetSpecificMetadata psMD)
 {
     this.Initialize(psMD);
 }
Exemple #21
0
        internal XmlDocument BuildXmlFromComments()
        {
            this.doc = new XmlDocument();
            XmlElement element1 = this.doc.CreateElement("command:command", HelpCommentsParser.commandURI);

            element1.SetAttribute("xmlns:maml", HelpCommentsParser.mamlURI);
            element1.SetAttribute("xmlns:command", HelpCommentsParser.commandURI);
            element1.SetAttribute("xmlns:dev", HelpCommentsParser.devURI);
            this.doc.AppendChild((XmlNode)element1);
            XmlElement element2 = this.doc.CreateElement("command:details", HelpCommentsParser.commandURI);

            element1.AppendChild((XmlNode)element2);
            XmlElement element3  = this.doc.CreateElement("command:name", HelpCommentsParser.commandURI);
            XmlText    textNode1 = this.doc.CreateTextNode(this.commandName);

            element2.AppendChild((XmlNode)element3).AppendChild((XmlNode)textNode1);
            if (!string.IsNullOrEmpty(this.sections.synopsis))
            {
                XmlElement element4  = this.doc.CreateElement("maml:description", HelpCommentsParser.mamlURI);
                XmlElement element5  = this.doc.CreateElement("maml:para", HelpCommentsParser.mamlURI);
                XmlText    textNode2 = this.doc.CreateTextNode(this.sections.synopsis);
                element2.AppendChild((XmlNode)element4).AppendChild((XmlNode)element5).AppendChild((XmlNode)textNode2);
            }
            this.DetermineParameterDescriptions();
            XmlElement element6 = this.doc.CreateElement("command:syntax", HelpCommentsParser.commandURI);
            MergedCommandParameterMetadata parameterMetadata = this.commandMetadata.StaticCommandParameterMetadata;

            if (parameterMetadata.ParameterSetCount > 0)
            {
                for (int i = 0; i < parameterMetadata.ParameterSetCount; ++i)
                {
                    this.BuildSyntaxForParameterSet(element1, element6, parameterMetadata, i);
                }
            }
            else
            {
                this.BuildSyntaxForParameterSet(element1, element6, parameterMetadata, int.MaxValue);
            }
            XmlElement element7 = this.doc.CreateElement("command:parameters", HelpCommentsParser.commandURI);

            foreach (KeyValuePair <string, MergedCompiledCommandParameter> bindableParameter in parameterMetadata.BindableParameters)
            {
                MergedCompiledCommandParameter commandParameter = bindableParameter.Value;
                if (commandParameter.BinderAssociation != ParameterBinderAssociation.CommonParameters)
                {
                    string key = bindableParameter.Key;
                    string parameterDescription = this.GetParameterDescription(key);
                    ParameterSetSpecificMetadata specificMetadata = (ParameterSetSpecificMetadata)null;
                    bool   isMandatory       = false;
                    bool   valueFromPipeline = false;
                    bool   valueFromPipelineByPropertyName = false;
                    string position = "named";
                    int    num      = 0;
                    CompiledCommandParameter parameter = commandParameter.Parameter;
                    parameter.ParameterSetData.TryGetValue("__AllParameterSets", out specificMetadata);
                    while (specificMetadata == null && num < 32)
                    {
                        specificMetadata = parameter.GetParameterSetData((uint)(1 << num++));
                    }
                    if (specificMetadata != null)
                    {
                        isMandatory       = specificMetadata.IsMandatory;
                        valueFromPipeline = specificMetadata.ValueFromPipeline;
                        valueFromPipelineByPropertyName = specificMetadata.ValueFromPipelineByPropertyName;
                        position = specificMetadata.IsPositional ? (1 + specificMetadata.Position).ToString((IFormatProvider)CultureInfo.InvariantCulture) : "named";
                    }
                    XmlElement xmlElement = this.BuildXmlForParameter(key, isMandatory, valueFromPipeline, valueFromPipelineByPropertyName, position, parameter.Type, parameterDescription, false);
                    element7.AppendChild((XmlNode)xmlElement);
                }
            }
            element1.AppendChild((XmlNode)element7);
            if (!string.IsNullOrEmpty(this.sections.description))
            {
                XmlElement element4  = this.doc.CreateElement("maml:description", HelpCommentsParser.mamlURI);
                XmlElement element5  = this.doc.CreateElement("maml:para", HelpCommentsParser.mamlURI);
                XmlText    textNode2 = this.doc.CreateTextNode(this.sections.description);
                element1.AppendChild((XmlNode)element4).AppendChild((XmlNode)element5).AppendChild((XmlNode)textNode2);
            }
            if (!string.IsNullOrEmpty(this.sections.notes))
            {
                XmlElement element4  = this.doc.CreateElement("maml:alertSet", HelpCommentsParser.mamlURI);
                XmlElement element5  = this.doc.CreateElement("maml:alert", HelpCommentsParser.mamlURI);
                XmlElement element8  = this.doc.CreateElement("maml:para", HelpCommentsParser.mamlURI);
                XmlText    textNode2 = this.doc.CreateTextNode(this.sections.notes);
                element1.AppendChild((XmlNode)element4).AppendChild((XmlNode)element5).AppendChild((XmlNode)element8).AppendChild((XmlNode)textNode2);
            }
            if (this.sections.examples.Count > 0)
            {
                XmlElement element4 = this.doc.CreateElement("command:examples", HelpCommentsParser.commandURI);
                int        num      = 1;
                foreach (string example in this.sections.examples)
                {
                    XmlElement element5  = this.doc.CreateElement("command:example", HelpCommentsParser.commandURI);
                    XmlElement element8  = this.doc.CreateElement("maml:title", HelpCommentsParser.mamlURI);
                    XmlText    textNode2 = this.doc.CreateTextNode(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "\t\t\t\t-------------------------- {0} {1} --------------------------", (object)ResourceManagerCache.GetResourceString("HelpDisplayStrings", "ExampleUpperCase"), (object)num++));
                    element5.AppendChild((XmlNode)element8).AppendChild((XmlNode)textNode2);
                    string prompt_str;
                    string code_str;
                    string remarks_str;
                    this.GetExampleSections(example, out prompt_str, out code_str, out remarks_str);
                    XmlElement element9  = this.doc.CreateElement("maml:introduction", HelpCommentsParser.mamlURI);
                    XmlElement element10 = this.doc.CreateElement("maml:para", HelpCommentsParser.mamlURI);
                    XmlText    textNode3 = this.doc.CreateTextNode(prompt_str);
                    element5.AppendChild((XmlNode)element9).AppendChild((XmlNode)element10).AppendChild((XmlNode)textNode3);
                    XmlElement element11 = this.doc.CreateElement("dev:code", HelpCommentsParser.devURI);
                    XmlText    textNode4 = this.doc.CreateTextNode(code_str);
                    element5.AppendChild((XmlNode)element11).AppendChild((XmlNode)textNode4);
                    XmlElement element12 = this.doc.CreateElement("dev:remarks", HelpCommentsParser.devURI);
                    XmlElement element13 = this.doc.CreateElement("maml:para", HelpCommentsParser.mamlURI);
                    XmlText    textNode5 = this.doc.CreateTextNode(remarks_str);
                    element5.AppendChild((XmlNode)element12).AppendChild((XmlNode)element13).AppendChild((XmlNode)textNode5);
                    for (int index = 0; index < 4; ++index)
                    {
                        element12.AppendChild((XmlNode)this.doc.CreateElement("maml:para", HelpCommentsParser.mamlURI));
                    }
                    element4.AppendChild((XmlNode)element5);
                }
                element1.AppendChild((XmlNode)element4);
            }
            if (this.sections.inputs.Count > 0)
            {
                XmlElement element4 = this.doc.CreateElement("command:inputTypes", HelpCommentsParser.commandURI);
                foreach (string input in this.sections.inputs)
                {
                    XmlElement element5  = this.doc.CreateElement("command:inputType", HelpCommentsParser.commandURI);
                    XmlElement element8  = this.doc.CreateElement("dev:type", HelpCommentsParser.devURI);
                    XmlElement element9  = this.doc.CreateElement("maml:name", HelpCommentsParser.mamlURI);
                    XmlText    textNode2 = this.doc.CreateTextNode(input);
                    element4.AppendChild((XmlNode)element5).AppendChild((XmlNode)element8).AppendChild((XmlNode)element9).AppendChild((XmlNode)textNode2);
                }
                element1.AppendChild((XmlNode)element4);
            }
            IEnumerable enumerable = (IEnumerable)null;

            if (this.sections.outputs.Count > 0)
            {
                enumerable = (IEnumerable)this.sections.outputs;
            }
            else if (this.scriptBlock.OutputType.Count > 0)
            {
                enumerable = (IEnumerable)this.scriptBlock.OutputType;
            }
            if (enumerable != null)
            {
                XmlElement element4 = this.doc.CreateElement("command:returnValues", HelpCommentsParser.commandURI);
                foreach (object obj in enumerable)
                {
                    XmlElement element5 = this.doc.CreateElement("command:returnValue", HelpCommentsParser.commandURI);
                    XmlElement element8 = this.doc.CreateElement("dev:type", HelpCommentsParser.devURI);
                    XmlElement element9 = this.doc.CreateElement("maml:name", HelpCommentsParser.mamlURI);
                    if (!(obj is string text))
                    {
                        text = ((PSTypeName)obj).Name;
                    }
                    XmlText textNode2 = this.doc.CreateTextNode(text);
                    element4.AppendChild((XmlNode)element5).AppendChild((XmlNode)element8).AppendChild((XmlNode)element9).AppendChild((XmlNode)textNode2);
                }
                element1.AppendChild((XmlNode)element4);
            }
            if (this.sections.links.Count > 0)
            {
                XmlElement element4 = this.doc.CreateElement("maml:relatedLinks", HelpCommentsParser.mamlURI);
                foreach (string link in this.sections.links)
                {
                    XmlElement element5  = this.doc.CreateElement("maml:navigationLink", HelpCommentsParser.mamlURI);
                    XmlElement element8  = this.doc.CreateElement(Uri.IsWellFormedUriString(Uri.EscapeUriString(link), UriKind.Absolute) ? "maml:uri" : "maml:linkText", HelpCommentsParser.mamlURI);
                    XmlText    textNode2 = this.doc.CreateTextNode(link);
                    element4.AppendChild((XmlNode)element5).AppendChild((XmlNode)element8).AppendChild((XmlNode)textNode2);
                }
                element1.AppendChild((XmlNode)element4);
            }
            return(this.doc);
        }
        /// <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);
        }
        } // EvaluateUnboundPositionalParameters

        private static void AddNewPosition(
            SortedDictionary<int, Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter>> result,
            int positionInParameterSet,
            MergedCompiledCommandParameter parameter,
            ParameterSetSpecificMetadata parameterSetData)
        {
            Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter> positionalCommandParameters;
            if (result.TryGetValue(positionInParameterSet, out positionalCommandParameters))
            {
                // Check to see if any of the other parameters in this position are in the same parameter set.
                if (ContainsPositionalParameterInSet(positionalCommandParameters, parameter, parameterSetData.ParameterSetFlag))
                {
                    // Multiple parameters were found with the same
                    // position. This means the parameter set is ambiguous.

                    // positional parameter could not be resolved

                    // We throw InvalidOperationException, which the
                    // caller will catch and throw a more
                    // appropriate exception.
                    throw PSTraceSource.NewInvalidOperationException();
                }

                PositionalCommandParameter positionalCommandParameter;
                if (!positionalCommandParameters.TryGetValue(parameter, out positionalCommandParameter))
                {
                    positionalCommandParameter = new PositionalCommandParameter(parameter);
                    positionalCommandParameters.Add(parameter, positionalCommandParameter);
                }
                positionalCommandParameter.ParameterSetData.Add(parameterSetData);
            }
            else
            {
                Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter> newPositionDictionary =
                    new Dictionary<MergedCompiledCommandParameter, PositionalCommandParameter>();

                PositionalCommandParameter newPositionalParameter = new PositionalCommandParameter(parameter);
                newPositionalParameter.ParameterSetData.Add(parameterSetData);
                newPositionDictionary.Add(parameter, newPositionalParameter);

                result.Add(positionInParameterSet, newPositionDictionary);
            }
        }
 private int NewParameterSetPromptingData(Dictionary<int, ParameterSetPromptingData> promptingData, MergedCompiledCommandParameter parameter, ParameterSetSpecificMetadata parameterSetMetadata, int defaultParameterSet, bool pipelineInputExpected)
 {
     int num = 0;
     int parameterSetFlag = parameterSetMetadata.ParameterSetFlag;
     if (parameterSetFlag == 0)
     {
         parameterSetFlag = int.MaxValue;
     }
     bool isDefaultSet = (defaultParameterSet != 0) && ((defaultParameterSet & parameterSetFlag) != 0);
     bool flag2 = false;
     if (parameterSetMetadata.IsMandatory)
     {
         num |= parameterSetFlag;
         flag2 = true;
     }
     bool flag3 = false;
     if (pipelineInputExpected && (parameterSetMetadata.ValueFromPipeline || parameterSetMetadata.ValueFromPipelineByPropertyName))
     {
         flag3 = true;
     }
     if (flag2)
     {
         ParameterSetPromptingData data;
         if (!promptingData.TryGetValue(parameterSetFlag, out data))
         {
             data = new ParameterSetPromptingData(parameterSetFlag, isDefaultSet);
             promptingData.Add(parameterSetFlag, data);
         }
         if (flag3)
         {
             data.PipelineableMandatoryParameters[parameter] = parameterSetMetadata;
             if (parameterSetMetadata.ValueFromPipeline)
             {
                 data.PipelineableMandatoryByValueParameters[parameter] = parameterSetMetadata;
             }
             if (parameterSetMetadata.ValueFromPipelineByPropertyName)
             {
                 data.PipelineableMandatoryByPropertyNameParameters[parameter] = parameterSetMetadata;
             }
             return num;
         }
         data.NonpipelineableMandatoryParameters[parameter] = parameterSetMetadata;
     }
     return num;
 }
Exemple #25
0
 private static void AddNewPosition(SortedDictionary <int, Dictionary <MergedCompiledCommandParameter, PositionalCommandParameter> > result, int positionInParameterSet, MergedCompiledCommandParameter parameter, ParameterSetSpecificMetadata parameterSetData)
 {
     if (result.ContainsKey(positionInParameterSet))
     {
         Dictionary <MergedCompiledCommandParameter, PositionalCommandParameter> positionalCommandParameters = result[positionInParameterSet];
         if (ContainsPositionalParameterInSet(positionalCommandParameters, parameter, parameterSetData.ParameterSetFlag))
         {
             throw PSTraceSource.NewInvalidOperationException();
         }
         if (positionalCommandParameters.ContainsKey(parameter))
         {
             positionalCommandParameters[parameter].ParameterSetData.Add(parameterSetData);
         }
         else
         {
             PositionalCommandParameter parameter2 = new PositionalCommandParameter(parameter);
             parameter2.ParameterSetData.Add(parameterSetData);
             positionalCommandParameters.Add(parameter, parameter2);
         }
     }
     else
     {
         Dictionary <MergedCompiledCommandParameter, PositionalCommandParameter> dictionary2 = new Dictionary <MergedCompiledCommandParameter, PositionalCommandParameter>();
         PositionalCommandParameter parameter3 = new PositionalCommandParameter(parameter)
         {
             ParameterSetData = { parameterSetData }
         };
         dictionary2.Add(parameter, parameter3);
         result.Add(positionInParameterSet, dictionary2);
     }
 }