public ExtensionMethodFinder(DocumentModel model) { _lookup = new Dictionary<string, HashSet<DocumentedMethod>>(StringComparer.Ordinal); // Find all extension methods. foreach (var method in model.Assemblies .SelectMany(assembly => assembly.Namespaces) .SelectMany(ns => ns.Types) .SelectMany(type => type.Methods) .Where(method => method.MethodClassification == MethodClassification.ExtensionMethod)) { try { var extensionParameter = method.Parameters[0]; var fullName = extensionParameter.Definition.ParameterType.Resolve()?.FullName ?? (extensionParameter.Definition.ParameterType as Mono.Cecil.GenericParameter)?.Constraints.FirstOrDefault()?.Resolve().FullName; if (fullName == null) { Debug.WriteLine("Failed to resolve Name: {0}, Parameter: {1}, ParameterType: {2}", method.Definition.FullName, extensionParameter.Definition.Name, extensionParameter.Definition.ParameterType); continue; } if (!_lookup.ContainsKey(fullName)) { _lookup.Add(fullName, new HashSet<DocumentedMethod>()); } _lookup[fullName].Add(method); } catch (Exception) { // Resolution failed. } } }
public ExtensionMethodFinder(DocumentModel model) { _lookup = new Dictionary<string, HashSet<DocumentedMethod>>(StringComparer.Ordinal); // Find all extension methods. foreach (var method in model.Assemblies .SelectMany(assembly => assembly.Namespaces) .SelectMany(ns => ns.Types) .SelectMany(type => type.Methods) .Where(method => method.MethodClassification == MethodClassification.ExtensionMethod)) { try { var parameterType = method.Parameters[0].Definition.ParameterType.Resolve(); if (!_lookup.ContainsKey(parameterType.FullName)) { _lookup.Add(parameterType.FullName, new HashSet<DocumentedMethod>()); } _lookup[parameterType.FullName].Add(method); } catch (Exception) { // Resolution failed. } } }
public SignatureCache(DocumentModel model, UrlResolver resolver) { _resolver = resolver; _documentedTypes = new ConcurrentDictionary<DocumentedType, TypeSignature>(new DocumentedTypeComparer()); _typeReferences = new ConcurrentDictionary<TypeReference, TypeSignature>(new TypeReferenceComparer()); _documentedMethods = new ConcurrentDictionary<DocumentedMethod, MethodSignature>(new DocumentedMethodComparer()); foreach (var @namespace in model.Assemblies.SelectMany(a => a.Namespaces)) { foreach (var type in @namespace.Types) { var typeSignature = type.Definition.GetTypeSignature(_resolver); _documentedTypes.TryAdd(type, typeSignature); _typeReferences.TryAdd(type.Definition, typeSignature); foreach (var method in type.Methods .Concat(type.Constructors) .Concat(type.Operators)) { var methodSignature = method.Definition.GetMethodSignature(_resolver); _documentedMethods.TryAdd(method, methodSignature); } } } }
public SignatureRenderer( DocumentModel model, LanguageProvider language) { _typeRenderer = new TypeRenderer(model, language); _methodRenderer = new MethodRenderer(_typeRenderer); _languageProvider = new LanguageProvider(); }
public ApiViewModel(DocumentModel model) { _assemblies = new List<AssemblyViewModel>(); foreach (var assembly in model.Assemblies) { _assemblies.Add(new AssemblyViewModel(assembly)); } }
public BaseTypeFinder(DocumentModel model) { _lookup = new Dictionary<string, DocumentedType>(StringComparer.Ordinal); foreach (var type in model.Assemblies .SelectMany(assembly => assembly.Namespaces .SelectMany(@namespace => @namespace.Types))) { _lookup.Add(type.Definition.FullName, type); } }
public static DslModel Build(DocumentModel model) { Dictionary<string, SummaryComment> summaries; var data = GetData(model, out summaries); var categories = new List<DslCategory>(); foreach (var categoryName in data.Keys) { var metadata = (IDocumentationMetadata)null; var categoryMethods = new List<DocumentedMethod>(); var subCategories = new List<DslSubCategory>(); foreach (var subCategoryName in data[categoryName].Keys) { var methods = data[categoryName][subCategoryName]; if (string.IsNullOrWhiteSpace(subCategoryName)) { categoryMethods.AddRange(methods.OrderBy(x => x.Identity)); } else { subCategories.Add(new DslSubCategory(subCategoryName, methods)); } if (metadata == null) { metadata = methods.First().Metadata; } } SummaryComment summary = null; if (summaries.ContainsKey(categoryName)) { summary = summaries[categoryName]; } categories.Add( new DslCategory( categoryName, metadata, summary, categoryMethods, subCategories.OrderBy(x => x.Name))); } var dslModel = new DslModel(categories.OrderBy(x => x.Name)); foreach (var category in dslModel.Categories) { category.Parent = dslModel; } return dslModel; }
private static Dictionary<string, Dictionary<string, List<DocumentedMethod>>> GetData(DocumentModel model, out Dictionary<string, SummaryComment> summaries) { var result = new Dictionary<string, Dictionary<string, List<DocumentedMethod>>>(); summaries = new Dictionary<string, SummaryComment> { {"General", new SummaryComment(new[] { new InlineTextComment("Contains miscellaneous functionality.") })} }; foreach (var assembly in model.Assemblies) { foreach (var ns in assembly.Namespaces) { foreach (var type in ns.Types) { var typeCategory = GetCategory(type.Definition.CustomAttributes); var parentCategory = typeCategory ?? "General"; var categorySummary = type.Summary; if (!summaries.ContainsKey(parentCategory) && categorySummary != null) { summaries.Add(parentCategory, categorySummary); } foreach (var method in type.Methods) { bool isPropertyAlias; if (IsCakeAlias(method, out isPropertyAlias)) { var methodCategory = GetCategory(method.Definition.CustomAttributes); var category = methodCategory ?? string.Empty; if (!result.ContainsKey(parentCategory)) { result.Add(parentCategory, new Dictionary<string, List<DocumentedMethod>>()); } if (!result[parentCategory].ContainsKey(category)) { result[parentCategory].Add(category, new List<DocumentedMethod>()); } result[parentCategory][category].Add(method); } } } } } return result; }
public UrlResolver(DocumentModel model, RouteService service) { _service = service; _routeLookup = new Dictionary<string, string>(); // Assemblies foreach (var assembly in model.Assemblies) { // Namespaces foreach (var @namespace in assembly.Namespaces) { if (!_routeLookup.ContainsKey(@namespace.Identity)) { // Namespaces are tricky since they might exist in multiple assemblies. _routeLookup.Add(@namespace.Identity, GetUrl(@namespace)); } // Types foreach (var type in @namespace.Types) { _routeLookup.Add(type.Identity, GetUrl(type)); // Constructors foreach (var method in type.Constructors) { _routeLookup.Add(method.Identity, GetUrl(method)); } // Methods foreach (var method in type.Methods) { _routeLookup.Add(method.Identity, GetUrl(method)); } // Operators foreach (var method in type.Operators) { _routeLookup.Add(method.Identity, GetUrl(method)); } // Properties foreach (var property in type.Properties) { _routeLookup.Add(property.Identity, GetUrl(property)); } } } } }
public ApiServices( DocumentModel model, DocumentModelResolver documentModelResolver, UrlResolver urlResolver, SignatureRenderer signatureRenderer, LanguageProvider languageProvider, SyntaxRenderer syntaxRenderer, SignatureCache signatureResolver) { Model = model; ModelResolver = documentModelResolver; UrlResolver = urlResolver; SignatureRenderer = signatureRenderer; LanguageProvider = languageProvider; SyntaxRenderer = syntaxRenderer; SignatureResolver = signatureResolver; }
/// <summary> /// Generates a document model from a <see cref="ReflectionModel"/> /// and a <see cref="XmlDocumentationModel"/>. /// </summary> /// <param name="reflectionModel">The reflection model.</param> /// <param name="xmlModel">The XML documentation model.</param> /// <returns>A document model.</returns> public static DocumentModel Map(ReflectionModel reflectionModel, XmlDocumentationModel xmlModel) { var assemblies = new List<DocumentedAssembly>(); // Iterate all assemblies. foreach (var assembly in reflectionModel.Assemblies) { assemblies.Add(MapAssembly(assembly, xmlModel)); } // Create the document model. var model = new DocumentModel(assemblies); // Map extension methods. var finder = new ExtensionMethodFinder(model); var namespaces = model.Assemblies.SelectMany(a => a.Namespaces).ToArray(); foreach (var @namespace in namespaces) { foreach (var type in @namespace.Types) { type.SetExtensionMethods(finder.FindExtensionMethods(type)); } } // Map base types methods. var baseTypeFinder = new BaseTypeFinder(model); foreach (var @namespace in namespaces) { foreach (var type in @namespace.Types) { type.BaseType = baseTypeFinder.FindBaseType(type); } } // Build namespace trees and map them. var trees = DocumentedNamespaceTree.Build(namespaces); foreach (var @namespace in namespaces) { if (trees.ContainsKey(@namespace.Identity)) { @namespace.Tree = trees[@namespace.Identity]; } } return model; }
public RouteService(DocumentModel model) { _namespaces = new Dictionary<string, List<DocumentedNamespace>>(); _types = new Dictionary<string, DocumentedType>(); _members = new Dictionary<string, DocumentedMember>(); // Cache information for fast lookup. foreach (var @namespace in model.Assemblies.SelectMany(assembly => assembly.Namespaces)) { // Namespace var namespaceRoute = GetRoutePart(@namespace); if (!_namespaces.ContainsKey(namespaceRoute)) { _namespaces.Add(namespaceRoute, new List<DocumentedNamespace>()); } _namespaces[namespaceRoute].Add(@namespace); // Types foreach (var type in @namespace.Types) { _types.Add(GetRoutePart(type), type); // Constructors foreach (var constructor in type.Constructors) { _members.Add(GetRoutePart(constructor), constructor); } // Methods foreach (var method in type.Methods) { _members.Add(GetRoutePart(method), method); } // Operators foreach (var @operator in type.Operators) { _members.Add(GetRoutePart(@operator), @operator); } // Properties foreach (var property in type.Properties) { _members.Add(GetRoutePart(property), property); } } } }
public TypeRenderer(DocumentModel model, LanguageProvider language) { _model = model; _language = language; }
/// <summary> /// Initializes a new instance of the <see cref="DocumentModelResolver"/> class. /// </summary> /// <param name="model">The model.</param> public DocumentModelResolver(DocumentModel model) { _model = model; }
/// <summary> /// Initializes a new instance of the <see cref="DocumentModelResolver"/> class. /// </summary> /// <param name="model">The model.</param> public DocumentModelResolver(DocumentModel model) { _model = model; }
public ApiController(DocumentModel model, RouteService router) { _model = model; _router = router; }