Пример #1
0
        private static TypeInfo CreateTypeInfo(Type type)
        {
            TypeInfo result;

            if (type == typeof(void))
            {
                result = new VoidTypeInfo();
            }
            else if (type.GetMethod("Parse", new[] { typeof(string) }) != null && type.GetMethod("Parse", new[] { typeof(string) }).ReturnType == type)
            {
                result = new ParseableTypeInfo(type);
            }
            else if (type.IsArray)
            {
                result = new ArrayTypeInfo(type);
            }
            else if (type.IsEnum)
            {
                result = new EnumTypeInfo(type);
            }
            else if (type.ContainsGenericParameters)
            {
                result = new ReflectedTypeInfo(type);
            }
            else if (OPTIMIZED_TYPES.Contains(type))
            {
                result = new OptimizedTypeInfo(type);
            }
            else
            {
                result = new ReflectedTypeInfo(type);
            }

            return(result);
        }
Пример #2
0
        public static List <ReflectedTypeInfo> GetPropertiesForType <T>()
        {
            var publicProps = new List <ReflectedTypeInfo>();

            var t = typeof(T);

            var bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;

            var props = t.GetProperties(bindingFlags);

            foreach (var prop in props)
            {
                var valueInfo = new ReflectedTypeInfo()
                {
                    IsNullableType = prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>),
                    IsPrivate      = prop.PropertyType.IsPublic,
                    Name           = prop.Name,
                };

                // Override strings to be a nullable type
                if (prop.PropertyType == typeof(string))
                {
                    valueInfo.IsNullableType = true;
                }

                // Override strings to be a nullable type
                if (prop.PropertyType == typeof(string))
                {
                    valueInfo.IsNullableType = true;
                    valueInfo.ValueType      = typeof(string);
                }
                else if (valueInfo.IsNullableType)
                {
                    // If the value type is nullable, get its underlying type
                    valueInfo.ValueType = prop.PropertyType.GetGenericArguments()[0];
                }
                else
                {
                    valueInfo.ValueType = prop.PropertyType;
                }

                publicProps.Add(valueInfo);
            }

            return(publicProps);
        }
Пример #3
0
 protected bool IsTypeInDocumentation(ReflectedTypeInfo x)
 {
     if (_assemblies.ContainsKey(x.Assembly))
     {
         if (!_namespaces.Any())
         {
             return(true);
         }
         foreach (string ns in _namespaces)
         {
             if (x.Namespace.StartsWith(ns))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #4
0
        private void BuildInheritanceChain(XDoc html, ReflectedTypeInfo type)
        {
            html.StartNameValueBlock("inheritance", "Type Hierarchy");
            var chain = GetParents(type.BaseType).ToList();

            foreach (var link in chain)
            {
                html.Start("ul")
                .Start("li");
                BuildParameterMarkup(html, link);
                html.End(); // li
            }
            html.Start("ul")
            .Start("li").Elem("b", type.DisplayName).End();
            var subclasses = (from t in _types
                              where t.BaseType != null && !t.BaseType.IsGenericParameter && t.BaseType.Type == type
                              select t).ToList();

            if (subclasses.Any())
            {
                html.Start("ul");
                foreach (var subclass in subclasses)
                {
                    html.Start("li");
                    if (IsTypeInDocumentation(subclass))
                    {
                        html.Link(subclass.UriPath, subclass.DisplayName);
                    }
                    else
                    {
                        html.Value(subclass.DisplayName);
                    }
                    html.End(); // li
                }
                html.End();     // subclass ul
            }
            html.End();         // type ul
            for (var i = 0; i < chain.Count; i++)
            {
                html.End();
            }
            html.EndNameValue();
        }
Пример #5
0
 private void BuildInterfaceBlock(XDoc html, ReflectedTypeInfo type)
 {
     if (type.Interfaces.Any())
     {
         html.StartNameValueBlock("implements", "Implements")
         .Start("ul");
         foreach (var interfaceParameter in type.Interfaces)
         {
             html.Start("li");
             BuildParameterMarkup(html, interfaceParameter);
             html.End();
         }
         html.End() // ul
         .EndNameValue();
     }
     if (type.Kind == TypeKind.Interface)
     {
         var implementers = (from t in _types where t.Interfaces.Where(x => x.Type == type).Any() select t).ToList();
         if (implementers.Any())
         {
             html.StartNameValueBlock("implementors", "Implementors")
             .Start("ul");
             foreach (var implementor in implementers)
             {
                 html.Start("li");
                 if (IsTypeInDocumentation(implementor))
                 {
                     html.Link(implementor.UriPath, implementor.DisplayName);
                 }
                 else
                 {
                     html.Value(implementor.DisplayName);
                 }
                 html.End();
             }
             html.End() // ul
             .EndNameValue();
         }
     }
 }
Пример #6
0
        private void AddMemberTables(XDoc html, ReflectedTypeInfo type)
        {
            if (!type.Constructors.Any() && !type.Fields.Any() && !type.Properties.Any() && !type.Methods.Any() && !type.Events.Any())
            {
                return;
            }
            html.StartSection(1, "members", "Members");

            if (type.Constructors.Any())
            {
                html.StartSection(2, "ctors", "Constructors")
                .Start("table")
                .Start("tr").Elem("th", "Visibility").Elem("th", "Description").End();
                foreach (var member in type.Constructors.OrderBy(x => x.DisplayName))
                {
                    BuildConstructorRow(html, member);
                }
                html.End() // table
                .EndSection();
            }
            if (type.Fields.Any())
            {
                html.StartSection(2, "fields", "Fields")
                .Start("table")
                .Start("tr").Elem("th", "Visibility").Elem("th", "Description").End();
                foreach (var member in type.Fields.OrderBy(x => x.DisplayName))
                {
                    BuildFieldRow(html, member);
                }
                html.End() // table
                .EndSection();
            }
            if (type.Properties.Any())
            {
                html.StartSection(2, "properties", "Properties")
                .Start("table")
                .Start("tr").Elem("th", "Visibility").Elem("th", "Description").End();
                foreach (var member in type.Properties.OrderBy(x => x.DisplayName))
                {
                    BuildPropertyRow(html, member);
                }
                html.End() // table
                .EndSection();
            }
            if (type.Methods.Any())
            {
                html.StartSection(2, "methods", "Methods")
                .Start("table")
                .Start("tr").Elem("th", "Visibility").Elem("th", "Description").End();
                foreach (var member in type.Methods.OrderBy(x => x.DisplayName))
                {
                    BuildMethodRow(html, member);
                }
                html.End() // table
                .EndSection();
            }
            if (type.Events.Any())
            {
                html.StartSection(2, "events", "Events")
                .Start("table")
                .Start("tr").Elem("th", "Visibility").Elem("th", "Description").End();
                foreach (var member in type.Events.OrderBy(x => x.DisplayName))
                {
                    BuildEventRow(html, member);
                }
                html.End() // table
                .EndSection();
            }
            html.EndSection(); //members
        }