Esempio n. 1
0
        public override string ToString()
        {
            var mb = new MarkdownBuilder();

            var desc = Comments.FirstOrDefault(x => x.MemberType == MemberType.Type)?.Summary ?? "";

            if (desc != "")
            {
                mb.AppendLine(desc);
            }
            {
                var sb = new StringBuilder();

                var stat = (_type.IsAbstract && _type.IsSealed) ? "static " : "";
                var abst = (_type.IsAbstract && !_type.IsInterface && !_type.IsSealed) ? "abstract " : "";
                var classOrStructOrEnumOrInterface = _type.IsInterface ? "interface" : _type.IsEnum ? "enum" : _type.IsValueType ? "struct" : "class";

                sb.AppendLine($"public {stat}{abst}{classOrStructOrEnumOrInterface} {CSharpBeautifier.BeautifyType(_type, isFull: true)}");
                var impl = string.Join(", ", new[] { _type.BaseType }.Concat(_type.Interfaces.Select(x => x.InterfaceType))
                                       .Where(x => x != null && x.FullName != "System.Object" && x.FullName != "System.ValueType")
                                       .Select(x => CSharpBeautifier.BeautifyType(x)));
                if (impl != "")
                {
                    sb.AppendLine("    : " + impl);
                }

                mb.Code("csharp", sb.ToString());
            }

            if (_package != null)
            {
                mb.Append("Package: ");
                mb.CodeQuote(_package.Name);

                if (TargetFrameworks.Any())
                {
                    mb.Append(" (targets: ");
                    mb.Append(string.Join(", ", TargetFrameworks.Select(tfm => MarkdownBuilder.MarkdownCodeQuote(tfm))));
                    mb.Append(")");
                }

                mb.AppendLine();
                mb.AppendLine();
            }


            mb.Append("Assembly: ");
            mb.CodeQuote($"{this.AssymblyName}.dll");
            mb.AppendLine();
            mb.AppendLine();


            if (_type.IsEnum)
            {
                var enums = _type.Fields
                            .Where(x => x.Name != "value__")
                            .Select(x => new { Name = x.Name, Value = Convert.ToInt64(x.Constant) })
                            .OrderBy(x => x.Value)
                            .ToArray();

                BuildTable(mb, "Enum", enums, Comments, x => MarkdownBuilder.MarkdownCodeQuote(x.Value.ToString()), x => x.Name, x => x.Name);
            }
            else
            {
                BuildTable(mb, "Constructors", GetConstructors(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.ReturnType), x => x.Name, x => CSharpBeautifier.ToMarkdownMethodInfo(_library, x));
                BuildTable(mb, "Fields", GetFields(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Properties", GetProperties(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Events", GetEvents(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.EventType), x => x.Name, x => x.Name);
                BuildTable(mb, "Methods", GetMethods(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.ReturnType), x => x.Name, x => CSharpBeautifier.ToMarkdownMethodInfo(_library, x));
                BuildTable(mb, "Static Fields", GetStaticFields(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Properties", GetStaticProperties(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Methods", GetStaticMethods(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.ReturnType), x => x.Name, x => CSharpBeautifier.ToMarkdownMethodInfo(_library, x));
                BuildTable(mb, "Static Events", GetStaticEvents(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.EventType), x => x.Name, x => x.Name);
            }

            return(mb.ToString());
        }