public static IHtmlString TypeUrl(this ApiServices context, DocumentedType type) { if (type != null) { return TypeUrl(context, type.Identity); } return MvcHtmlString.Create(string.Empty); }
public static IHtmlString BreadCrumb(this ApiServices context, DocumentedType type) { var breadcrumb = new Breadcrumb(); breadcrumb.AppendApiRoot(); breadcrumb.AppendNamespaces(context, type.Namespace, true); breadcrumb.AppendType(context, type, false); return breadcrumb.Render(); }
public static IHtmlString TypeLink(this ApiServices context, DocumentedType type) { if (type != null) { var signature = context.SignatureResolver.GetTypeSignature(type); return context.SignatureRenderer.Render(signature, TypeRenderOption.Name | TypeRenderOption.Link); } return MvcHtmlString.Empty; }
private static bool IsExtensionMethodClass(DocumentedType type) { // TODO: Cache this if (!type.Identity.Contains("Alias")) { return type.Definition.IsClass && type.Definition.IsStatic() && type.Methods.All(x => x.MethodClassification == MethodClassification.ExtensionMethod); } return false; }
public TypeSignature GetTypeSignature(DocumentedType type) { TypeSignature signature; if (_documentedTypes.TryGetValue(type, out signature)) { return signature; } var message = string.Format("Could not find signature for {0}.", type.Identity); throw new InvalidOperationException(message); }
public TypeViewModel(DocumentedType data) { Data = data; Namespace = data.Namespace; Constructors = new List<DocumentedMethod>(data.Constructors); Methods = new List<DocumentedMethod>(data.Methods); ExtensionMethods = new List<DocumentedMethod>(data.ExtensionMethods); Operators = new List<DocumentedMethod>(data.Operators); Properties = new List<DocumentedProperty>(GetProperties(data)); Fields = new List<DocumentedField>(data.Fields); }
public TypeViewModel(DocumentedType data) { _data = data; _namespace = data.Namespace; _constructors = new List<DocumentedMethod>(data.Constructors); _methods = new List<DocumentedMethod>(data.Methods); _extensionMethods = new List<DocumentedMethod>(data.ExtensionMethods); _operators = new List<DocumentedMethod>(data.Operators); _properties = new List<DocumentedProperty>(GetProperties(data)); _fields = new List<DocumentedField>(data.Fields); }
public List <DocumentedMethod> FindExtensionMethods(DocumentedType type) { var methods = new List <DocumentedMethod>(); var current = type.Definition; while (current != null) { if (current.FullName == "System.Object") { // Skip extension methods for System.Object. break; } // Found extension methods for the current type? if (_lookup.ContainsKey(current.FullName)) { methods.AddRange(_lookup[current.FullName]); } // Found extension methods for the current types interfaces? foreach (var typeReference in current.Interfaces) { if (_lookup.ContainsKey(typeReference.FullName)) { methods.AddRange(_lookup[typeReference.FullName]); } } // Get the base type. var baseType = current.BaseType; if (baseType != null) { try { // Resolve the type. current = baseType.Resolve(); } catch (Exception) { // Resolution failed. current = null; } } else { current = null; } } return(methods); }
public DocumentedType FindBaseType(DocumentedType type) { var baseType = type.Definition.BaseType; if (baseType != null) { if (baseType.FullName != "System.Object" && baseType.FullName != "System.ValueType") { DocumentedType value = null; _lookup.TryGetValue(baseType.FullName, out value); return value; } } return null; }
public List<DocumentedMethod> FindExtensionMethods(DocumentedType type) { var methods = new List<DocumentedMethod>(); var current = type.Definition; while (current != null) { if (current.FullName == "System.Object") { // Skip extension methods for System.Object. break; } // Found extension methods for the current type? if (_lookup.ContainsKey(current.FullName)) { methods.AddRange(_lookup[current.FullName]); } // Found extension methods for the current types interfaces? foreach (var typeReference in current.Interfaces) { if (_lookup.ContainsKey(typeReference.InterfaceType.FullName)) { methods.AddRange(_lookup[typeReference.InterfaceType.FullName]); } } // Get the base type. var baseType = current.BaseType; if (baseType != null) { try { // Resolve the type. current = baseType.Resolve(); } catch (Exception) { // Resolution failed. current = null; } } else { current = null; } } return methods; }
public DocumentedType FindBaseType(DocumentedType type) { var baseType = type.Definition.BaseType; if (baseType != null) { if (baseType.FullName != "System.Object" && baseType.FullName != "System.ValueType") { DocumentedType value = null; _lookup.TryGetValue(baseType.FullName, out value); return(value); } } return(null); }
public static IHtmlString TypeClassificationName(this ApiServices context, DocumentedType type) { if (type != null) { switch (type.TypeClassification) { case TypeClassification.Class: return MvcHtmlString.Create("Class"); case TypeClassification.Enum: return MvcHtmlString.Create("Enumeration"); case TypeClassification.Interface: return MvcHtmlString.Create("Interface"); case TypeClassification.Struct: return MvcHtmlString.Create("Struct"); default: return MvcHtmlString.Create("Unknown"); } } return MvcHtmlString.Create(string.Empty); }
private static IEnumerable<DocumentedProperty> GetProperties(DocumentedType type) { return type.Properties.Where(p => !p.Definition.GetMethod.IsExplicitlyImplemented()); }
private string GetUrl(DocumentedType type) { var nsRoute = _service.GetRoutePart(type.Namespace); var typeRoute = _service.GetRoutePart(type); return string.Concat(nsRoute, "/", typeRoute); }
private Dictionary<string, List<IHtmlString>> GetGenericParameterConstraints(DocumentedType type) { var parameters = type.Definition.GenericParameters.Where(p => p.HasConstraints || p.HasReferenceTypeConstraint || p.HasDefaultConstructorConstraint || p.HasNotNullableValueTypeConstraint).ToArray(); var result = new Dictionary<string, List<IHtmlString>>(); if (parameters.Length > 0) { foreach (var parameter in parameters) { var constraints = new List<IHtmlString>(); if (parameter.HasNotNullableValueTypeConstraint) { constraints.Add(MvcHtmlString.Create("struct")); } if (parameter.HasReferenceTypeConstraint) { constraints.Add(MvcHtmlString.Create("class")); } foreach (var constraint in parameter.Constraints) { if (constraint.FullName == "System.ValueType") { continue; } constraints.Add(_renderer.Render(constraint.GetTypeSignature(_urlResolver), TypeRenderOption.Name | TypeRenderOption.Link)); } if (parameter.HasDefaultConstructorConstraint && !parameter.HasNotNullableValueTypeConstraint) { constraints.Add(MvcHtmlString.Create("new()")); } result.Add(parameter.FullName, constraints); } } return result; }
private List<IHtmlString> GetBaseTypes(DocumentedType type) { var result = new List<IHtmlString>(); var baseType = type.Definition.BaseType; if (baseType != null) { if (baseType.FullName != "System.Object" && baseType.FullName != "System.ValueType") { result.Add(_renderer.Render(baseType.GetTypeSignature(_urlResolver), TypeRenderOption.Name | TypeRenderOption.Link)); } foreach (var @interface in type.Definition.Interfaces) { result.Add(_renderer.Render(@interface.GetTypeSignature(_urlResolver), TypeRenderOption.Name | TypeRenderOption.Link)); } } return result; }
public bool TryFindTypeFromRoutePart(string id, out DocumentedType type) { return _types.TryGetValue(id, out type); }
public string GetRoutePart(DocumentedType type) { return $"{type.Identity.GetHashCode():X8}".ToLowerInvariant(); }
public string GetRoutePart(DocumentedType type) { return string.Format("{0:X8}", type.Identity.GetHashCode()).ToLowerInvariant(); }
public static void AppendType(this IBreadcrumbItem breadcrumb, ApiServices context, DocumentedType type, bool link) { Uri uri = null; if (link) { uri = new Uri(context.UrlResolver.GetUrl(type.Identity), UriKind.Relative); } var signature = context.SignatureResolver.GetTypeSignature(type); breadcrumb.Append(new BreadcrumbItem(context.SignatureRenderer.Render(signature, TypeRenderOption.Name), uri)); }
public static IHtmlString Syntax(this ApiServices context, DocumentedType type) { var signature = context.SignatureResolver.GetTypeSignature(type); return context.SyntaxRenderer.Render(signature); }