public static MemberDom Build(TypeDom typeDom, MemberInfo memberInfo, XElement doc) { MemberDom ret; if (memberInfo is MethodInfo) { ret = new MethodDom(memberInfo as MethodInfo, doc); } else if (memberInfo is ConstructorInfo) { ret = new ConstructorDom(memberInfo as ConstructorInfo, doc); } else if (memberInfo is PropertyInfo) { ret = new PropertyDom(memberInfo as PropertyInfo, doc); } else if (memberInfo is EventInfo) { ret = new EventDom(memberInfo as EventInfo, doc); } else if (memberInfo is FieldInfo) { ret = new FieldDom(memberInfo as FieldInfo, doc); } else { throw new Exception(); } ret.Type = typeDom; //ToTo: передавать конструктор? Иначе в конструкторе _typeDom==null return(ret); }
public static MemberDom Build(TypeDom typeDom, MemberInfo memberInfo, XElement doc) { MemberDom ret; switch (memberInfo) { case MethodInfo method: ret = new MethodDom(method, doc); break; case ConstructorInfo ctor: ret = new ConstructorDom(ctor, doc); break; case PropertyInfo prop: ret = new PropertyDom(prop, doc); break; case EventInfo evt: ret = new EventDom(evt, doc); break; case FieldInfo field: ret = new FieldDom(field, doc); break; default: throw new Exception(); } ret.Type = typeDom; //ToTo: передавать конструктор? Иначе в конструкторе _typeDom==null return(ret); }
public static AssemblyDom Build(AssemblyDoc asmDoc, Assembly asm, Func <MemberDom, bool> filterMembers, FindOptions findOptions) { var ret = new AssemblyDom { _name = asmDoc.Name, ReflectionAssembly = asm }; asmDoc.MergeWithReflection(asm, findOptions, out ret.ErrorUnboundTypes, out ret.ErrorUnboundMembers); ret.AllTypes = asmDoc.Types.Select(_ => TypeDom.Build(_, ret, filterMembers)).ToArray(); ret.FillNamespaces(); ret.FillNestedTypes(); return(ret); }
static void FillNestedTypesRec(Dictionary <string, TypeDom> dict, TypeDom typeDom) { foreach (var ntype in typeDom.Type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic)) { if (dict.TryGetValue(TypeUtils.GetNameWithNamespaceShortGeneric(ntype), out var nestedTypeDom)) { if (typeDom.NestedTypes == null) { typeDom.NestedTypes = new TypeDom[0]; } typeDom.NestedTypes = typeDom.NestedTypes .Concat(Enumerable.Repeat(nestedTypeDom, 1)) .ToArray(); FillNestedTypesRec(dict, nestedTypeDom); } } }
public static MemberDom Build(TypeDom typeDom, MemberInfo memberInfo, XElement doc) { MemberDom ret; if (memberInfo is MethodInfo) ret = new MethodDom(memberInfo as MethodInfo, doc); else if (memberInfo is ConstructorInfo) ret = new ConstructorDom(memberInfo as ConstructorInfo, doc); else if (memberInfo is PropertyInfo) ret = new PropertyDom(memberInfo as PropertyInfo, doc); else if (memberInfo is EventInfo) ret = new EventDom(memberInfo as EventInfo, doc); else if (memberInfo is FieldInfo) ret = new FieldDom(memberInfo as FieldInfo, doc); else throw new Exception(); ret.Type = typeDom; //ToTo: передавать конструктор? Иначе в конструкторе _typeDom==null return ret; }
public static TypeDom Build(TypeDoc doc, AssemblyDom asm, Func <MemberDom, bool> filterMembers) { var ret = new TypeDom { Assembly = asm, DocInfo = doc.DocInfo, Type = doc.ReflectionType, }; MemberDom[] members = doc.Members .Where(_ => _.ReflectionMemberInfo != null) .Select(_ => MemberDom.Build(ret, _.ReflectionMemberInfo, _.DocInfo)) .ToArray(); members = members.Where( _ => (filterMembers == null || filterMembers(_)) && !_.IsPrivateOrInternal ).ToArray(); ret.AllMembers = members; ret.Constructors = members.OfType <ConstructorDom>().OrderBy(_ => _.ShortSignature).ToArray(); ret.Fields = members.OfType <FieldDom>() .OrderBy(_ => _.ShortSignature) .ToArray(); ret.Properties = members.OfType <PropertyDom>() .OrderBy(_ => _.ShortSignature) .ToArray(); ret.Methods = members.OfType <MethodDom>() .Where(_ => !_.IsOperator) .OrderBy(_ => _.ShortSignature) .ToArray(); ret.Operators = members.OfType <MethodDom>() .Where(_ => _.IsOperator) .OrderBy(_ => _.ShortSignature) .ToArray(); ret.Events = members.OfType <EventDom>() .OrderBy(_ => _.ShortSignature) .ToArray(); ret.GenericTypeParameters = GenericParameterDom.BuildTypeGenericParameters(ret.Type, ret.DocInfo); return(ret); }
static XElement BuildNsSection(TypeDom.TypeKindEnum kind, TypeDom[] types) { if (!types.Any()) return null; XElement tbody; var ret = Section( Names[kind + "_s"], x("table", a("class", "doc_table"), tbody = x("tbody")) ); tbody.Add(BuildRow(new XElement[0], x("span", Names[Strings.Name]), Names[Strings.Description].ToSpan(), "th")); foreach (var type in types) tbody.Add(BuildRow( Enumerable.Repeat(GetImage(Navigation.GetIconCss((kind + (type.Type.IsPublic ? "Pub" : "Prot")).To<MemberIconsEnum>()), Names[kind.ToString()], Navigation.EmptyImage, Names[kind.ToString()]), 1), BuildTypeUrl(type.Type, false), XMLUtils.GetTagInnerXml(type.DocInfo, "summary", Navigation, false) )); return ret; }
static string Generate(TypeDom type) { XElement body; var doc = GetDoc(out body); body.Add( x("h1", type.GetDisplayName(false) + Names[Strings.SuffixDelimeter] + Names[type.TypeKind.ToString()]), x("p", XMLUtils.GetTagInnerXml(type.DocInfo, "summary", Navigation, true)), InheritanceSection(type), NamespaceAssembly(type.Type), GenerateSyntax(type), BuldParameters(Names[Strings.TypeParameters], type.GenericTypeParameters) ); for (int i = 0; i <= (int)MemberTypeSection.Events; i++) { body.Add(BuildMembers((MemberTypeSection)i, type)); } body.Add(BuildEnding(type.Assembly, type.DocInfo)); return doc.ToString(); }
public TypePartialData(TypeDom type, MemberTypeSection sectionType) { Type = type; SectionType = sectionType; }
private static XElement GenerateSyntax(TypeDom type) { var parts = new List<XElement>(); foreach (var attr in type.Type.GetAttributes(false).Where(a1 => a1.GetType() != typeof(ExtensionAttribute))) { parts.Add(BuildTypeUrl(attr.GetType(), false, true)); parts.Add(x("br")); } parts.Add(x("span", type.Type.IsPublic ? "public" : "protected", a("style", "color:Blue;"))); if (type.Type.IsStatic()) parts.Add(x("span", "static", a("style", "color:Blue;"))); parts.Add(x("span", type.TypeKind.ToString().ToLowerInvariant(), a("style", "color:Blue;"))); parts.Add(x("span", type.Name)); var interfaces = type.Type.GetInterfaces(); if (type.TypeKind == TypeDom.TypeKindEnum.Class) { if (type.Type.BaseType != typeof(object) || interfaces.Length > 0) { parts.Add(x("span", " : ")); if (type.Type.BaseType != typeof(object)) { parts.Add(BuildTypeUrl(type.Type.BaseType, false)); if (interfaces.Length > 0) parts.Add(x("span", ",")); } foreach (var itf in interfaces) { parts.Add(BuildTypeUrl(itf, false)); parts.Add(x("span", ",")); } if (interfaces.Length > 0) parts.RemoveAt(parts.Count - 1); } } else if (type.TypeKind == TypeDom.TypeKindEnum.Enum) { if (type.Type.GetEnumBaseType() != typeof(int)) { parts.Add(x("span", " : ")); parts.Add(BuildTypeUrl(type.Type.BaseType, false)); } } else if (type.TypeKind == TypeDom.TypeKindEnum.Interface || type.TypeKind == TypeDom.TypeKindEnum.Struct) { if (interfaces.Length > 0) { parts.Add(x("span", " : ")); foreach (var itf in interfaces) { parts.Add(BuildTypeUrl(itf, false)); parts.Add(x("span", ",")); } if (interfaces.Length > 0) parts.RemoveAt(parts.Count - 1); } } return x("div", a("class", "doc_syntax"), x("code", parts)); }
static XElement BuildMembers(MemberTypeSection section, TypeDom type) { switch (section) { case MemberTypeSection.NestedTypes: return BuildNestedTypes(type.NestedTypes); case MemberTypeSection.Constructors: return BuildMembers(Strings.Constructors, type.Constructors); case MemberTypeSection.Properties: return BuildMembers(Strings.Properties, type.Properties); case MemberTypeSection.Methods: return BuildMembers(Strings.Methods, type.Methods); case MemberTypeSection.ExtentionMethods: return BuildMembers(Strings.ExtentionMethods, type.ExtentionMethods, true); case MemberTypeSection.Operators: return BuildMembers(Strings.Operators, type.Operators); case MemberTypeSection.Fields: return BuildMembers(Strings.Fields, type.Fields); case MemberTypeSection.Events: return BuildMembers(Strings.Events, type.Events); default: throw new Exception(); } }
static XElement InheritanceSection(TypeDom type) { if (type.Type.IsValueType || type.Type.IsEnum || type.Type.IsInterface || type.Type.IsSubclassOf(typeof(Delegate))) return x("div"); var space = string.Empty; var content = new XElement("div"); var baseTypes = type.BaseTypes; var derivedTypes = type.DerivedTypes; if (baseTypes.Length == 0 && derivedTypes.Length == 0) return null; foreach (var baseType in baseTypes) { content.Add(space, BuildTypeUrl(baseType), x("br")); space += Nbsp + Nbsp; } content.Add(x("b", space + type.GetDisplayName(true)), x("br")); space += Nbsp + Nbsp; foreach (var derivedType in derivedTypes) content.Add(space, BuildTypeUrl(derivedType), x("br")); return Section(Names[Strings.InheritanceHierarchy], content, a("class", "doc_inheritance")); }
public static TypeDom Build(TypeDoc doc, AssemblyDom asm, Func<MemberDom, bool> filterMembers) { var ret = new TypeDom { Assembly = asm, DocInfo = doc.DocInfo, Type = doc.ReflectionType, }; MemberDom[] members = doc.Members .Where(_ => _.ReflectionMemberInfo != null) .Select(_ => MemberDom.Build(ret, _.ReflectionMemberInfo, _.DocInfo)) .ToArray(); members = members.Where( _ => (filterMembers==null || filterMembers(_)) && !_.IsPrivateOrInternal ).ToArray(); ret.AllMembers = members; ret.Constructors = members.OfType<ConstructorDom>().OrderBy(_ => _.ShortSignature).ToArray(); ret.Fields = members.OfType<FieldDom>() .OrderBy(_ => _.ShortSignature) .ToArray(); ret.Properties = members.OfType<PropertyDom>() .OrderBy(_ => _.ShortSignature) .ToArray(); ret.Methods = members.OfType<MethodDom>() .Where(_ => !_.IsOperator) .OrderBy(_ => _.ShortSignature) .ToArray(); ret.Operators = members.OfType<MethodDom>() .Where(_ => _.IsOperator) .OrderBy(_ => _.ShortSignature) .ToArray(); ret.Events = members.OfType<EventDom>() .OrderBy(_ => _.ShortSignature) .ToArray(); ret.GenericTypeParameters = GenericParameterDom.BuildTypeGenericParameters(ret.Type, ret.DocInfo); return ret; }
static void FillNestedTypesRec(Dictionary<string, TypeDom> dict, TypeDom typeDom) { foreach (var ntype in typeDom.Type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic)) { TypeDom nestedTypeDom; if (dict.TryGetValue(TypeUtils.GetNameWithNamespaceShortGeneric(ntype), out nestedTypeDom)) { if(typeDom.NestedTypes==null) typeDom.NestedTypes=new TypeDom[0]; typeDom.NestedTypes = typeDom.NestedTypes .Concat(Enumerable.Repeat(nestedTypeDom, 1)) .ToArray(); FillNestedTypesRec(dict, nestedTypeDom); } } }
private static void AddMembers(OfflineDynamicPage parentNode, TypeDom type, MemberDom[] members, MemberTypeSection section) { if (members == null || members.Length == 0) return; var sectionItem = new OfflineDynamicPage { Parent = parentNode, UrlPart = parentNode.UrlPart + "/" + section.ToString(), RussianTitle = GenerateHtml.GetSectionName(section), RussianContent = GenerateHtml.Generate(new TypePartialData { SectionType = section, Type = type }), }; if (section == MemberTypeSection.Methods || section == MemberTypeSection.ExtentionMethods) GenerateMethods((MethodDom[])members, sectionItem, parentNode.UrlPart); else { foreach (var member in members) { //ToDo: Группировка переопределенных методов. var memberItem = new OfflineDynamicPage { Parent = sectionItem, UrlPart = parentNode.UrlPart + "/" + member.SimpleName, RussianTitle = member.ShortSignature, RussianContent = GenerateHtml.Generate(member), }; sectionItem.Childs.Add(memberItem); } } parentNode.Childs.Add(sectionItem); }