Beispiel #1
0
        protected virtual void WriteExample(TextWriter writer, ParameterSetCollection parameterSets, HelpLevel level)
        {
            const string indent = "   ";
            writer.WriteLine("EXAMPLES");

            var entryAsm = Assembly.GetEntryAssembly();
            string fileName = "";
            if (entryAsm != null)
                fileName = Path.GetFileName(Assembly.GetEntryAssembly().Location);

            foreach (var set in parameterSets)
            {
                var examples =
                    set.SelectMany(p => p.GetAttributes<ExampleValueAttribute>()
                                         .Select(ev => new Tuple<Parameter, ExampleValueAttribute>(p, ev)))
                       .GroupBy(t => t.Item2.Set,
                                StringComparer.InvariantCultureIgnoreCase);

                examples = examples.Where(g => g.Any(t => t.Item1.Property.DeclaringType == set.UnderlyingType));

                foreach (IGrouping<string, Tuple<Parameter, ExampleValueAttribute>> group in examples)
                {
                    var attrDict = group.ToDictionary(t => t.Item1, t => t.Item2);
                    this.WriteSyntax(writer,
                                     new[] { set },
                                     indent,
                                     fileName,
                                     false,
                                     p =>
                                     {
                                         ExampleValueAttribute attr;
                                         if (attrDict.TryGetValue(p, out attr))
                                             return true;
                                         return p.GetAttribute<RequiredAttribute>() != null;
                                     },
                                     p =>
                                     {
                                         ExampleValueAttribute attr;
                                         if (attrDict.TryGetValue(p, out attr))
                                             return attr.Value;

                                         if (p.Property.PropertyType == typeof(Switch))
                                             return "";

                                         if (level.HasFlag(HelpLevel.Detailed))
                                             return string.Format("<{0}>", p.Property.PropertyType.FullName);

                                         return string.Format("<{0}>", this.GetHumanReadableTypeName(p.Property.PropertyType));
                                     });
                }
            }
        }
Beispiel #2
0
        protected virtual void WriteSyntax(TextWriter writer, IEnumerable<ParameterSet> parameterSets, HelpLevel level)
        {
            const string indent = "   ";
            writer.WriteLine("SYNTAX");
            var entryAsm = Assembly.GetEntryAssembly();
            string fileName = "";
            if (entryAsm != null)
                fileName = Path.GetFileName(Assembly.GetEntryAssembly().Location);

            this.WriteSyntax(writer,
                             parameterSets,
                             indent,
                             fileName,
                             true,
                             p => true,
                             p =>
                             {
                                 if (p.Property.PropertyType == typeof(Switch))
                                     return "";

                                 if (p.Property.PropertyType == typeof(Switch))
                                     return "";

                                 if (level.HasFlag(HelpLevel.Detailed))
                                     return string.Format("<{0}>", p.Property.PropertyType.FullName);

                                 return string.Format("<{0}>", this.GetHumanReadableTypeName(p.Property.PropertyType));
                             });
        }
Beispiel #3
0
        public virtual void Write(TextWriter writer, ParameterSetCollection sets, HelpLevel level)
        {
            if (level.HasFlag(HelpLevel.Syntax))
            {
                this.WriteSyntax(writer, sets, level);
            }

            if (level.HasFlag(HelpLevel.Examples))
            {
                this.WriteExample(writer, sets, level);
            }

            if (level.HasFlag(HelpLevel.Parameters))
            {
                this.WriteParameters(writer, sets, level);
            }
        }