public static List <DocumentedMember> GetFields(Type type) { var result = new List <DocumentedMember>(); foreach (var field in type.GetFields()) { var documentedMember = new DocumentedMember(); documentedMember.Signature = string.Format("{0} {1}", FixPrimitives(GetFriendlyTypeName(field.FieldType)), field.Name); documentedMember.Description = GetDescription(field); result.Add(documentedMember); } return(result); }
public static List <DocumentedMember> GetProperties(Type type) { var result = new List <DocumentedMember>(); foreach (var property in type.IsInterface ? type.GetProperties() : type.GetProperties(BindingFlags.DeclaredOnly)) { var documentedMember = new DocumentedMember(); documentedMember.Signature = string.Format("{0} {1}", FixPrimitives(GetFriendlyTypeName(property.PropertyType)), property.Name); documentedMember.Description = GetDescription(property); result.Add(documentedMember); } return(result); }
public static List<DocumentedMember> GetConstructors(Type type) { var result = new List<DocumentedMember>(); var constructors = type.GetConstructors().Where(c => c.GetParameters().Count() > 0); foreach (var constructor in constructors) { var documentedMember = new DocumentedMember(); var parameters = constructor.GetParameters(); documentedMember.Signature = string.Format("{0}({1})", GetFriendlyTypeName(type), GetParameterString(parameters)); documentedMember.Description = GetDescription(constructor); result.Add(documentedMember); } return result; }
public static List <DocumentedMember> GetConstructors(Type type) { var result = new List <DocumentedMember>(); var constructors = type.GetConstructors().Where(c => c.GetParameters().Count() > 0); foreach (var constructor in constructors) { var documentedMember = new DocumentedMember(); var parameters = constructor.GetParameters(); documentedMember.Signature = string.Format("{0}({1})", GetFriendlyTypeName(type), GetParameterString(parameters)); documentedMember.Description = GetDescription(constructor); result.Add(documentedMember); } return(result); }
public static List <DocumentedMember> GetExtensions(Type extensionsType, Type type) { var extensions = from method in extensionsType.GetMethods(BindingFlags.Static | BindingFlags.Public) where method.IsDefined(typeof(ExtensionAttribute), false) where method.GetParameters()[0].ParameterType == type select method; var extensionType = type.Assembly.GetTypes().FirstOrDefault(t => { var name = type.Name; var tick = name.IndexOf('`'); if (tick > 0) { name = name.Substring(0, tick); } return(t.Name == name + "Extensions"); }); if (extensionType != null) { extensions = extensions.Concat(from method in extensionType.GetMethods(BindingFlags.Static | BindingFlags.Public) where method.IsDefined(typeof(ExtensionAttribute), false) select method); } var result = new List <DocumentedMember>(); foreach (var method in extensions) { var documentedMember = new DocumentedMember(); documentedMember.Signature = GetSignature(method, true); documentedMember.Description = GetDescription(method); result.Add(documentedMember); } return(result); }
public static List <DocumentedMember> GetMethods(Type type) { var result = new List <DocumentedMember>(); foreach (var method in type.IsInterface ? type.GetMethods() : type.GetMethods(BindingFlags.DeclaredOnly)) { if (method.IsSpecialName) { continue; } var documentedMember = new DocumentedMember(); documentedMember.Signature = GetSignature(method, false); documentedMember.Description = GetDescription(method); result.Add(documentedMember); } return(result); }
public DocumentedType(Type extensionsType, Type type) { Type = type; Constructors = DocumentedMember.GetConstructors(type); Properties = DocumentedMember.GetProperties(type); Methods = DocumentedMember.GetMethods(type); if (extensionsType != null) { Extensions = DocumentedMember.GetExtensions(extensionsType, type); } if (type.IsValueType && !type.IsPrimitive) // is struct (?) { Fields = DocumentedMember.GetFields(type); } else { Fields = new List <DocumentedMember>(); } }
public static List<DocumentedMember> GetExtensions(Type extensionsType, Type type) { var extensions = from method in extensionsType.GetMethods(BindingFlags.Static | BindingFlags.Public) where method.IsDefined(typeof(ExtensionAttribute), false) where method.GetParameters()[0].ParameterType == type select method; var extensionType = type.Assembly.GetTypes().FirstOrDefault(t => { var name = type.Name; var tick = name.IndexOf('`'); if (tick > 0) name = name.Substring(0, tick); return t.Name == name + "Extensions"; }); if (extensionType != null) extensions = extensions.Concat(from method in extensionType.GetMethods(BindingFlags.Static | BindingFlags.Public) where method.IsDefined(typeof(ExtensionAttribute), false) select method); var result = new List<DocumentedMember>(); foreach (var method in extensions) { var documentedMember = new DocumentedMember(); documentedMember.Signature = GetSignature(method, true); documentedMember.Description = GetDescription(method); result.Add(documentedMember); } return result; }
public static List<DocumentedMember> GetFields(Type type) { var result = new List<DocumentedMember>(); foreach (var field in type.GetFields()) { var documentedMember = new DocumentedMember(); documentedMember.Signature = string.Format("{0} {1}", FixPrimitives(GetFriendlyTypeName(field.FieldType)), field.Name); documentedMember.Description = GetDescription(field); result.Add(documentedMember); } return result; }
public static List<DocumentedMember> GetProperties(Type type) { var result = new List<DocumentedMember>(); foreach (var property in type.IsInterface ? type.GetProperties() : type.GetProperties(BindingFlags.DeclaredOnly)) { var documentedMember = new DocumentedMember(); documentedMember.Signature = string.Format("{0} {1}", FixPrimitives(GetFriendlyTypeName(property.PropertyType)), property.Name); documentedMember.Description = GetDescription(property); result.Add(documentedMember); } return result; }
public static List<DocumentedMember> GetMethods(Type type) { var result = new List<DocumentedMember>(); foreach (var method in type.IsInterface ? type.GetMethods() : type.GetMethods(BindingFlags.DeclaredOnly)) { if (method.IsSpecialName) continue; var documentedMember = new DocumentedMember(); documentedMember.Signature = GetSignature(method, false); documentedMember.Description = GetDescription(method); result.Add(documentedMember); } return result; }
static void DocumentAssemblyAtPath(string assemblyToDocument) { var fileName = assemblyToDocument.Replace(".dll", "Docs.html"); Console.WriteLine("Documenting assembly " + assemblyToDocument + " in file " + fileName); var assembly = Assembly.LoadFrom(assemblyToDocument); if (File.Exists(fileName)) { File.Delete(fileName); } var file = File.Open(fileName, FileMode.Create); var tw = new StreamWriter(file); var extensionType = assembly.GetTypes().Where(et => et.Name == "Extensions").First(); var types = assembly.GetExportedTypes() .OrderBy(t => ((t.IsInterface ? "0" : "1") + "." + t.Name)) .Where(t => !t.Name.Contains("Extensions") && !t.Namespace.Contains("LitJson")) .Select(t => new DocumentedType(extensionType, t)); tw.WriteLine("<ul>"); foreach (var type in types) { tw.WriteLine(string.Format("<li><a href=\"#{0}\">{1}</a></li>", type.FragmentName, HttpUtility.HtmlEncode(type.FriendlyName))); } tw.WriteLine("</ul>"); foreach (var type in types) { Console.WriteLine("Documenting type " + type.Type.Namespace + "." + type.Type.Name + "..."); tw.WriteLine(string.Format("<a name=\"{0}\"></a><h2>{1}</h2>", type.FragmentName, HttpUtility.HtmlEncode(DocumentedMember.GetFriendlyTypeName(type.Type)))); tw.WriteLine(Transform(type.Description.Trim())); if (type.Constructors.Count > 0) { WriteMemberList(tw, type.Constructors, "Constructors"); } if (type.Properties.Count > 0) { WriteMemberList(tw, type.Properties, "Properties"); } if (type.Methods.Count > 0) { WriteMemberList(tw, type.Methods, "Methods"); } if (type.Extensions.Count > 0) { WriteMemberList(tw, type.Extensions, "Extensions"); } if (type.Fields.Count > 0) { WriteMemberList(tw, type.Fields, "Fields"); } } tw.Flush(); file.Flush(); file.Close(); }