상속: Cake.Web.Docs.DocumentedMember
예제 #1
0
 public static IHtmlString TypeUrl(this ApiServices context, DocumentedType type)
 {
     if (type != null)
     {
         return TypeUrl(context, type.Identity);
     }
     return MvcHtmlString.Create(string.Empty);
 }
예제 #2
0
 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();
 }
예제 #3
0
 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;
 }
예제 #4
0
 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;
 }
예제 #5
0
 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);
 }
예제 #6
0
 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);
 }
예제 #7
0
 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);
        }
예제 #9
0
 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;
 }
예제 #10
0
        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;
        }
예제 #11
0
        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);
        }
예제 #12
0
 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);
 }
예제 #13
0
 private static IEnumerable<DocumentedProperty> GetProperties(DocumentedType type)
 {
     return type.Properties.Where(p => !p.Definition.GetMethod.IsExplicitlyImplemented());
 }
예제 #14
0
 private string GetUrl(DocumentedType type)
 {
     var nsRoute = _service.GetRoutePart(type.Namespace);
     var typeRoute = _service.GetRoutePart(type);
     return string.Concat(nsRoute, "/", typeRoute);
 }
예제 #15
0
        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;
        }
예제 #16
0
 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;
 }
예제 #17
0
 public bool TryFindTypeFromRoutePart(string id, out DocumentedType type)
 {
     return _types.TryGetValue(id, out type);
 }
예제 #18
0
 public string GetRoutePart(DocumentedType type)
 {
     return $"{type.Identity.GetHashCode():X8}".ToLowerInvariant();
 }
예제 #19
0
 public string GetRoutePart(DocumentedType type)
 {
     return string.Format("{0:X8}", type.Identity.GetHashCode()).ToLowerInvariant();
 }
예제 #20
0
 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));
 }
예제 #21
0
 public static IHtmlString Syntax(this ApiServices context, DocumentedType type)
 {
     var signature = context.SignatureResolver.GetTypeSignature(type);
     return context.SyntaxRenderer.Render(signature);
 }