示例#1
0
        private static void WriteSyntaxItem(XmlWriter writer, string cmdletName, string setName, CmdletParameterSetPartitions parameterSetPartitioning)
        {
            var isCustomNamedSet  = !setName.Equals(CmdletParameterSetPartitions.AllSetsKey);
            var isDefaultSet      = isCustomNamedSet && setName.Equals(parameterSetPartitioning.DefaultParameterSetName, StringComparison.Ordinal);
            var setParameterNames = parameterSetPartitioning.ParameterNamesForSet(setName, parameterSetPartitioning.HasNamedParameterSets);

            writer.WriteStartElement("syntaxItem");
            {
                writer.WriteElementString("name", cmdletName);

                var allParameters = parameterSetPartitioning.Parameters;
                // Microsoft cmdlets show params in syntax in defined but non-alpha order. Use the ordering we found
                // during reflection here in the hope the sdk has them in 'most important' order
                foreach (var parameter in allParameters)
                {
                    if (!setParameterNames.Contains(parameter.CmdletParameterName))
                    {
                        continue;
                    }

                    InspectParameter(parameter, out var isRequiredForParametersets, out var pipelineInput, out var position, out var aliases);
                    var isRequiredForCurrentParameterset = isRequiredForParametersets != null && (isRequiredForParametersets.Count == 0 || isRequiredForParametersets.Contains(setName));

                    writer.WriteStartElement("parameter");
                    {
                        writer.WriteAttributeString("required", isRequiredForCurrentParameterset.ToString());
                        writer.WriteAttributeString("variableLength", "false");
                        writer.WriteAttributeString("globbing", "false");
                        writer.WriteAttributeString("pipelineInput", pipelineInput);
                        writer.WriteAttributeString("position", position);

                        writer.WriteElementString("name", parameter.CmdletParameterName);
                        writer.WriteStartElement("description");
                        {
                            writer.WriteRawElementString("para", parameter.PowershellDocumentation);
                        }
                        writer.WriteEndElement();

                        writer.WriteStartElement("parameterValue");
                        {
                            writer.WriteAttributeString("required", "true");
                            writer.WriteAttributeString("variableLength", "false");
                            writer.WriteString(parameter.PropertyTypeName);
                        }
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
            }
            writer.WriteEndElement();
        }
示例#2
0
        private static void AppendSyntaxChart(string cmdletName, string setName, CmdletParameterSetPartitions parameterSetPartitioning, StringBuilder sb)
        {
            var isCustomNamedSet = !setName.Equals(CmdletParameterSetPartitions.AllSetsKey);
            var isDefaultSet     = isCustomNamedSet && setName.Equals(parameterSetPartitioning.DefaultParameterSetName, StringComparison.Ordinal);

            var setParameterNames = parameterSetPartitioning.ParameterNamesForSet(setName, parameterSetPartitioning.HasNamedParameterSets);

            if (isCustomNamedSet)
            {
                sb.AppendFormat(
                    isDefaultSet
                        ? "<div class=\"paramsetname\"><h4>{0} (Default)</h4>"
                        : "<div class=\"paramsetname\"><h4>{0}</h4>", setName);
            }

            sb.Append("<div class=\"syntaxblock\">");

            // Microsoft cmdlets show params in syntax in defined but non-alpha order. Use the ordering we found
            // during reflection here in the hope the sdk has them in 'most important' order. Also, if there is
            // four or less params, keep the syntax on one line.
            sb.AppendFormat("<div class=\"cmdlet\">{0}</div>", cmdletName);
            var allParameters = parameterSetPartitioning.Parameters;
            var paramCount    = setParameterNames.Count;

            if (paramCount > 0)
            {
                sb.Append("<div class=\"paramlist\">");
                foreach (var p in allParameters)
                {
                    if (!setParameterNames.Contains(p.CmdletParameterName))
                    {
                        continue;
                    }

                    sb.AppendFormat("<div class=\"{0}\">-{1} &lt;{2}&gt;</div>",
                                    paramCount < 5 ? "inlineParam" : "wrappedParam",
                                    p.CmdletParameterName,
                                    GetTypeDisplayName(p.PropertyType, false));
                }
                sb.Append("</div>");
            }

            sb.Append("</div>");

            if (isCustomNamedSet)
            {
                sb.Append("</div>");
            }
        }