internal object GetDefaultScriptParameterValue(RuntimeDefinedParameter parameter, IList implicitUsingParameters = null) { object obj2 = parameter.Value; Compiler.DefaultValueExpressionWrapper wrapper = obj2 as Compiler.DefaultValueExpressionWrapper; if (wrapper != null) { obj2 = wrapper.GetValue(base.Context, this.Script.SessionStateInternal, implicitUsingParameters); } return(obj2); }
internal XmlDocument BuildXmlFromComments() { this.doc = new XmlDocument(); XmlElement newChild = this.doc.CreateElement("command:command", commandURI); newChild.SetAttribute("xmlns:maml", mamlURI); newChild.SetAttribute("xmlns:command", commandURI); newChild.SetAttribute("xmlns:dev", devURI); this.doc.AppendChild(newChild); XmlElement element2 = this.doc.CreateElement("command:details", commandURI); newChild.AppendChild(element2); XmlElement element3 = this.doc.CreateElement("command:name", commandURI); XmlText text = this.doc.CreateTextNode(this.commandName); element2.AppendChild(element3).AppendChild(text); if (!string.IsNullOrEmpty(this._sections.Synopsis)) { XmlElement element4 = this.doc.CreateElement("maml:description", mamlURI); XmlElement element5 = this.doc.CreateElement("maml:para", mamlURI); XmlText text2 = this.doc.CreateTextNode(this._sections.Synopsis); element2.AppendChild(element4).AppendChild(element5).AppendChild(text2); } this.DetermineParameterDescriptions(); XmlElement syntax = this.doc.CreateElement("command:syntax", commandURI); MergedCommandParameterMetadata staticCommandParameterMetadata = this.commandMetadata.StaticCommandParameterMetadata; if (staticCommandParameterMetadata.ParameterSetCount > 0) { for (int i = 0; i < staticCommandParameterMetadata.ParameterSetCount; i++) { this.BuildSyntaxForParameterSet(newChild, syntax, staticCommandParameterMetadata, i); } } else { this.BuildSyntaxForParameterSet(newChild, syntax, staticCommandParameterMetadata, 0x7fffffff); } XmlElement element7 = this.doc.CreateElement("command:parameters", commandURI); foreach (KeyValuePair <string, MergedCompiledCommandParameter> pair in staticCommandParameterMetadata.BindableParameters) { MergedCompiledCommandParameter parameter = pair.Value; if (parameter.BinderAssociation != ParameterBinderAssociation.CommonParameters) { ParameterSetSpecificMetadata parameterSetData; string key = pair.Key; string parameterDescription = this.GetParameterDescription(key); bool isMandatory = false; bool valueFromPipeline = false; bool valueFromPipelineByPropertyName = false; string position = "named"; int num2 = 0; CompiledCommandParameter parameter2 = parameter.Parameter; parameter2.ParameterSetData.TryGetValue("__AllParameterSets", out parameterSetData); while ((parameterSetData == null) && (num2 < 0x20)) { parameterSetData = parameter2.GetParameterSetData(((int)1) << num2++); } if (parameterSetData != null) { isMandatory = parameterSetData.IsMandatory; valueFromPipeline = parameterSetData.ValueFromPipeline; valueFromPipelineByPropertyName = parameterSetData.ValueFromPipelineByPropertyName; position = parameterSetData.IsPositional ? ((1 + parameterSetData.Position)).ToString(CultureInfo.InvariantCulture) : "named"; } Collection <System.Attribute> compiledAttributes = parameter2.CompiledAttributes; bool supportsWildcards = compiledAttributes.OfType <SupportsWildcardsAttribute>().Any <SupportsWildcardsAttribute>(); string help = ""; object obj2 = null; PSDefaultValueAttribute attribute = compiledAttributes.OfType <PSDefaultValueAttribute>().FirstOrDefault <PSDefaultValueAttribute>(); if (attribute != null) { help = attribute.Help; if (string.IsNullOrEmpty(help)) { obj2 = attribute.Value; } } if (string.IsNullOrEmpty(help)) { RuntimeDefinedParameter parameter3; if ((obj2 == null) && this.scriptBlock.RuntimeDefinedParameters.TryGetValue(key, out parameter3)) { obj2 = parameter3.Value; } Compiler.DefaultValueExpressionWrapper wrapper = obj2 as Compiler.DefaultValueExpressionWrapper; if (wrapper != null) { help = wrapper.Expression.Extent.Text; } else if (obj2 != null) { help = PSObject.ToStringParser(null, obj2); } } XmlElement element8 = this.BuildXmlForParameter(key, isMandatory, valueFromPipeline, valueFromPipelineByPropertyName, position, parameter2.Type, parameterDescription, supportsWildcards, help, false); element7.AppendChild(element8); } } newChild.AppendChild(element7); if (!string.IsNullOrEmpty(this._sections.Description)) { XmlElement element9 = this.doc.CreateElement("maml:description", mamlURI); XmlElement element10 = this.doc.CreateElement("maml:para", mamlURI); XmlText text3 = this.doc.CreateTextNode(this._sections.Description); newChild.AppendChild(element9).AppendChild(element10).AppendChild(text3); } if (!string.IsNullOrEmpty(this._sections.Notes)) { XmlElement element11 = this.doc.CreateElement("maml:alertSet", mamlURI); XmlElement element12 = this.doc.CreateElement("maml:alert", mamlURI); XmlElement element13 = this.doc.CreateElement("maml:para", mamlURI); XmlText text4 = this.doc.CreateTextNode(this._sections.Notes); newChild.AppendChild(element11).AppendChild(element12).AppendChild(element13).AppendChild(text4); } if (this._examples.Count > 0) { XmlElement element14 = this.doc.CreateElement("command:examples", commandURI); int num3 = 1; foreach (string str5 in this._examples) { string str7; string str8; string str9; XmlElement element15 = this.doc.CreateElement("command:example", commandURI); XmlElement element16 = this.doc.CreateElement("maml:title", mamlURI); string str6 = string.Format(CultureInfo.InvariantCulture, "\t\t\t\t-------------------------- {0} {1} --------------------------", new object[] { HelpDisplayStrings.ExampleUpperCase, num3++ }); XmlText text5 = this.doc.CreateTextNode(str6); element15.AppendChild(element16).AppendChild(text5); GetExampleSections(str5, out str7, out str8, out str9); XmlElement element17 = this.doc.CreateElement("maml:introduction", mamlURI); XmlElement element18 = this.doc.CreateElement("maml:para", mamlURI); XmlText text6 = this.doc.CreateTextNode(str7); element15.AppendChild(element17).AppendChild(element18).AppendChild(text6); XmlElement element19 = this.doc.CreateElement("dev:code", devURI); XmlText text7 = this.doc.CreateTextNode(str8); element15.AppendChild(element19).AppendChild(text7); XmlElement element20 = this.doc.CreateElement("dev:remarks", devURI); XmlElement element21 = this.doc.CreateElement("maml:para", mamlURI); XmlText text8 = this.doc.CreateTextNode(str9); element15.AppendChild(element20).AppendChild(element21).AppendChild(text8); for (int j = 0; j < 4; j++) { element20.AppendChild(this.doc.CreateElement("maml:para", mamlURI)); } element14.AppendChild(element15); } newChild.AppendChild(element14); } if (this._inputs.Count > 0) { XmlElement element22 = this.doc.CreateElement("command:inputTypes", commandURI); foreach (string str10 in this._inputs) { XmlElement element23 = this.doc.CreateElement("command:inputType", commandURI); XmlElement element24 = this.doc.CreateElement("dev:type", devURI); XmlElement element25 = this.doc.CreateElement("maml:name", mamlURI); XmlText text9 = this.doc.CreateTextNode(str10); element22.AppendChild(element23).AppendChild(element24).AppendChild(element25).AppendChild(text9); } newChild.AppendChild(element22); } IEnumerable outputType = null; if (this._outputs.Count > 0) { outputType = this._outputs; } else if (this.scriptBlock.OutputType.Count > 0) { outputType = this.scriptBlock.OutputType; } if (outputType != null) { XmlElement element26 = this.doc.CreateElement("command:returnValues", commandURI); foreach (object obj3 in outputType) { XmlElement element27 = this.doc.CreateElement("command:returnValue", commandURI); XmlElement element28 = this.doc.CreateElement("dev:type", devURI); XmlElement element29 = this.doc.CreateElement("maml:name", mamlURI); string str11 = (obj3 as string) ?? ((PSTypeName)obj3).Name; XmlText text10 = this.doc.CreateTextNode(str11); element26.AppendChild(element27).AppendChild(element28).AppendChild(element29).AppendChild(text10); } newChild.AppendChild(element26); } if (this._links.Count > 0) { XmlElement element30 = this.doc.CreateElement("maml:relatedLinks", mamlURI); foreach (string str12 in this._links) { XmlElement element31 = this.doc.CreateElement("maml:navigationLink", mamlURI); string qualifiedName = Uri.IsWellFormedUriString(Uri.EscapeUriString(str12), UriKind.Absolute) ? "maml:uri" : "maml:linkText"; XmlElement element32 = this.doc.CreateElement(qualifiedName, mamlURI); XmlText text11 = this.doc.CreateTextNode(str12); element30.AppendChild(element31).AppendChild(element32).AppendChild(text11); } newChild.AppendChild(element30); } return(this.doc); }