private string GetCmdletName(CommonCmdletMetadata cmdletMetadata) { string str = cmdletMetadata.Noun ?? this.cmdletizationMetadata.Class.DefaultNoun; return (cmdletMetadata.Verb + "-" + str); }
private CommandMetadata GetCommandMetadata(CommonCmdletMetadata cmdletMetadata) { string defaultParameterSetName = null; StaticCmdletMetadataCmdletMetadata metadata = cmdletMetadata as StaticCmdletMetadataCmdletMetadata; if ((metadata != null) && !string.IsNullOrEmpty(metadata.DefaultCmdletParameterSet)) { defaultParameterSetName = metadata.DefaultCmdletParameterSet; } System.Management.Automation.ConfirmImpact none = System.Management.Automation.ConfirmImpact.None; if (cmdletMetadata.ConfirmImpactSpecified) { none = (System.Management.Automation.ConfirmImpact) cmdletMetadata.ConfirmImpact; } Dictionary<string, ParameterMetadata> parameters = new Dictionary<string, ParameterMetadata>(StringComparer.OrdinalIgnoreCase); CommandMetadata metadata2 = new CommandMetadata(this.GetCmdletName(cmdletMetadata), CommandTypes.Cmdlet, true, defaultParameterSetName, none != System.Management.Automation.ConfirmImpact.None, none, false, false, false, parameters); if (!string.IsNullOrEmpty(cmdletMetadata.HelpUri)) { metadata2.HelpUri = cmdletMetadata.HelpUri; } return metadata2; }
private CommonCmdletMetadata Read20_CommonCmdletMetadata(bool isNullable, bool checkType) { XmlQualifiedName type = checkType ? base.GetXsiType() : null; bool flag = false; if (isNullable) { flag = base.ReadNull(); } if ((checkType && (type != null)) && ((type.Name != this.id21_CommonCmdletMetadata) || (type.Namespace != this.id2_Item))) { if ((type.Name != this.id24_Item) || (type.Namespace != this.id2_Item)) { throw base.CreateUnknownTypeException(type); } return this.Read44_Item(isNullable, false); } if (flag) { return null; } CommonCmdletMetadata o = new CommonCmdletMetadata(); string[] a = null; int index = 0; bool[] flagArray = new bool[5]; while (base.Reader.MoveToNextAttribute()) { if ((!flagArray[0] && (base.Reader.LocalName == this.id93_Verb)) && (base.Reader.NamespaceURI == this.id4_Item)) { o.Verb = base.Reader.Value; flagArray[0] = true; } else { if ((!flagArray[1] && (base.Reader.LocalName == this.id94_Noun)) && (base.Reader.NamespaceURI == this.id4_Item)) { o.Noun = base.Reader.Value; flagArray[1] = true; continue; } if ((base.Reader.LocalName == this.id47_Aliases) && (base.Reader.NamespaceURI == this.id4_Item)) { string[] strArray2 = base.Reader.Value.Split(null); for (int i = 0; i < strArray2.Length; i++) { a = (string[]) base.EnsureArrayIndex(a, index, typeof(string)); a[index++] = strArray2[i]; } continue; } if ((!flagArray[3] && (base.Reader.LocalName == this.id22_ConfirmImpact)) && (base.Reader.NamespaceURI == this.id4_Item)) { o.ConfirmImpact = this.Read19_ConfirmImpact(base.Reader.Value); o.ConfirmImpactSpecified = true; flagArray[3] = true; } else { if ((!flagArray[4] && (base.Reader.LocalName == this.id95_HelpUri)) && (base.Reader.NamespaceURI == this.id4_Item)) { o.HelpUri = base.CollapseWhitespace(base.Reader.Value); flagArray[4] = true; continue; } if (!base.IsXmlnsAttribute(base.Reader.Name)) { base.UnknownNode(o, ":Verb, :Noun, :Aliases, :ConfirmImpact, :HelpUri"); } } } } base.Reader.MoveToElement(); if (base.Reader.IsEmptyElement) { base.Reader.Skip(); o.Aliases = (string[]) base.ShrinkArray(a, index, typeof(string), true); return o; } base.Reader.ReadStartElement(); base.Reader.MoveToContent(); int whileIterations = 0; int readerCount = base.ReaderCount; while ((base.Reader.NodeType != XmlNodeType.EndElement) && (base.Reader.NodeType != XmlNodeType.None)) { if (base.Reader.NodeType == XmlNodeType.Element) { base.UnknownNode(o, ""); } else { base.UnknownNode(o, ""); } base.Reader.MoveToContent(); base.CheckReaderCount(ref whileIterations, ref readerCount); } o.Aliases = (string[]) base.ShrinkArray(a, index, typeof(string), true); base.ReadEndElement(); return o; }
private void WriteCmdletAliases(TextWriter output, CommonCmdletMetadata cmdletMetadata) { string cmdletName = this.GetCmdletName(cmdletMetadata); if (cmdletMetadata.Aliases != null) { foreach (string str2 in cmdletMetadata.Aliases) { output.WriteLine(@"Microsoft.PowerShell.Utility\Set-Alias -Name '{0}' -Value '{1}' -Force -Scope script", CommandMetadata.EscapeSingleQuotedString(str2), CommandMetadata.EscapeSingleQuotedString(cmdletName)); output.WriteLine(@"Microsoft.PowerShell.Core\Export-ModuleMember -Alias '{0}'", CommandMetadata.EscapeSingleQuotedString(str2)); this.aliasesToExport.Add(str2); } } }
private void Write20_CommonCmdletMetadata(string n, string ns, CommonCmdletMetadata o, bool isNullable, bool needType) { if (o == null) { if (isNullable) { base.WriteNullTagLiteral(n, ns); } } else { if (!needType) { Type type = o.GetType(); if (type != typeof(CommonCmdletMetadata)) { if (type != typeof(StaticCmdletMetadataCmdletMetadata)) { throw base.CreateUnknownTypeException(o); } this.Write44_Item(n, ns, (StaticCmdletMetadataCmdletMetadata) o, isNullable, true); return; } } base.WriteStartElement(n, ns, o, false, null); if (needType) { base.WriteXsiType("CommonCmdletMetadata", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11"); } base.WriteAttribute("Verb", "", o.Verb); base.WriteAttribute("Noun", "", o.Noun); string[] aliases = o.Aliases; if (aliases != null) { base.Writer.WriteStartAttribute(null, "Aliases", ""); for (int i = 0; i < aliases.Length; i++) { string str = aliases[i]; if (i != 0) { base.Writer.WriteString(" "); } base.WriteValue(str); } base.Writer.WriteEndAttribute(); } if (o.ConfirmImpactSpecified) { base.WriteAttribute("ConfirmImpact", "", this.Write19_ConfirmImpact(o.ConfirmImpact)); } base.WriteAttribute("HelpUri", "", o.HelpUri); bool confirmImpactSpecified = o.ConfirmImpactSpecified; base.WriteEndElement(o); } }
private CommandMetadata GetCommandMetadata(CommonCmdletMetadata cmdletMetadata) { string defaultParameterSetName = null; StaticCmdletMetadataCmdletMetadata staticCmdletMetadata = cmdletMetadata as StaticCmdletMetadataCmdletMetadata; if (staticCmdletMetadata != null) { if (!string.IsNullOrEmpty(staticCmdletMetadata.DefaultCmdletParameterSet)) { defaultParameterSetName = staticCmdletMetadata.DefaultCmdletParameterSet; } } var confirmImpact = System.Management.Automation.ConfirmImpact.None; if (cmdletMetadata.ConfirmImpactSpecified) { confirmImpact = (System.Management.Automation.ConfirmImpact)(int)cmdletMetadata.ConfirmImpact; } Dictionary<string, ParameterMetadata> parameters = new Dictionary<string, ParameterMetadata>(StringComparer.OrdinalIgnoreCase); CommandMetadata commandMetadata = new CommandMetadata( name: this.GetCmdletName(cmdletMetadata), commandType: CommandTypes.Cmdlet, isProxyForCmdlet: true, defaultParameterSetName: defaultParameterSetName, // this can only be figured out for static cmdlets - instance cmdlets have to set that separately supportsShouldProcess: confirmImpact != System.Management.Automation.ConfirmImpact.None, confirmImpact: confirmImpact, supportsPaging: false, supportsTransactions: false, positionalBinding: false, parameters: parameters); if (!string.IsNullOrEmpty(cmdletMetadata.HelpUri)) { commandMetadata.HelpUri = cmdletMetadata.HelpUri; } return commandMetadata; }
private string GetCmdletAttributes(CommonCmdletMetadata cmdletMetadata) { // Generate the script for the Alias and Obsolete Attribute if any is declared in CDXML StringBuilder attributes = new StringBuilder(150); if (cmdletMetadata.Aliases != null) { attributes.Append("[Alias('" + string.Join("','", cmdletMetadata.Aliases.Select(alias => CodeGeneration.EscapeSingleQuotedStringContent(alias))) + "')]"); _aliasesToExport.AddRange(cmdletMetadata.Aliases); } if (cmdletMetadata.Obsolete != null) { string obsoleteMsg = (cmdletMetadata.Obsolete.Message != null) ? ("'" + CodeGeneration.EscapeSingleQuotedStringContent(cmdletMetadata.Obsolete.Message) + "'") : string.Empty; string newline = (attributes.Length > 0) ? Environment.NewLine : string.Empty; attributes.AppendFormat(CultureInfo.InvariantCulture, "{0}[Obsolete({1})]", newline, obsoleteMsg); } return attributes.ToString(); }
private string GetCmdletName(CommonCmdletMetadata cmdletMetadata) { string noun = cmdletMetadata.Noun ?? _cmdletizationMetadata.Class.DefaultNoun; string verb = cmdletMetadata.Verb; return verb + "-" + noun; }
private CommonCmdletMetadata GetGetCmdletMetadata() { Dbg.Assert(_cmdletizationMetadata.Class.InstanceCmdlets != null, "Caller should verify presence of instance cmdlets"); CommonCmdletMetadata cmdletMetadata; if (_cmdletizationMetadata.Class.InstanceCmdlets.GetCmdlet != null) { cmdletMetadata = _cmdletizationMetadata.Class.InstanceCmdlets.GetCmdlet.CmdletMetadata; } else { cmdletMetadata = new CommonCmdletMetadata(); cmdletMetadata.Noun = _cmdletizationMetadata.Class.DefaultNoun; cmdletMetadata.Verb = VerbsCommon.Get; } Dbg.Assert(cmdletMetadata != null, "xsd should ensure that cmdlet metadata element is always present"); return cmdletMetadata; }