Exemple #1
0
        private string GenerateBases(DocumentationCategory category)
        {
            var builder    = new StringBuilder();
            var hasParent  = Type.BaseType != null && !_ignoredBases.Contains(Type.BaseType);
            var interfaces = Type.GetInterfaces().Where(t => !_ignoredInterfaces.Contains(t) && (Type.BaseType == null || !Type.BaseType.GetInterfaces().Contains(t)));

            if (hasParent || interfaces.Any())
            {
                builder.Append(category.Templates.BaseOpener);
            }

            if (hasParent)
            {
                builder.Append(category.GetLink(Type.BaseType));
            }

            var first = !hasParent;

            if (interfaces.Any())
            {
                foreach (var i in interfaces)
                {
                    if (!first)
                    {
                        builder.Append(category.Templates.BaseSeparator);
                    }

                    builder.Append(category.GetLink(i));
                    first = false;
                }
            }

            return(builder.ToString());
        }
Exemple #2
0
        private List <DocumentationType> GetTypes(DocumentationCategory category, string sectionName, IEnumerable <string> files)
        {
            var sectionTypes = new List <DocumentationType>();

            if (category != null)
            {
                var types = category.GetTypes();

                foreach (var file in files)
                {
                    var section = GetSection(file);

                    if (section == sectionName)
                    {
                        var contents = File.ReadAllText(file);

                        foreach (var type in types)
                        {
                            if (IsTypeInFile(type.Type, contents))
                            {
                                sectionTypes.Add(type);
                            }
                        }
                    }
                }
            }

            return(sectionTypes);
        }
Exemple #3
0
        private string GenerateGenerics(Type[] generics, DocumentationCategory category)
        {
            var members = GetMembers(generics, GenerateGenericParameter, category, category.Templates.GenericSeparator);

            return(!string.IsNullOrEmpty(members)
                                ? string.Format("{0}{1}{2}", _genericOpener, members, _genericCloser)
                                : "");
        }
Exemple #4
0
        private string GenerateConstructor(ConstructorInfo constructor, DocumentationCategory category)
        {
            var name       = DocumentationGenerator.GetCleanName(constructor.DeclaringType);
            var parameters = GenerateParameters(constructor.GetParameters(), category);

            return(category.Templates.Constructor
                   .Replace(_memberNameTag, name)
                   .Replace(_memberParametersTag, parameters));
        }
Exemple #5
0
 private string GetFilename(DocumentationCategory category)
 {
     return(category.TypeFilename
            .Replace(DocumentationGenerator.CategoryNameTag, category.Name)
            .Replace(DocumentationGenerator.CategoryNiceNameTag, category.NiceName)
            .Replace(DocumentationGenerator.CategoryIdTag, category.Id)
            .Replace(DocumentationGenerator.TypeNameTag, Name)
            .Replace(DocumentationGenerator.TypeNiceNameTag, NiceName)
            .Replace(DocumentationGenerator.TypeIdTag, Id));
 }
Exemple #6
0
 public DocumentationType(Type type, DocumentationCategory category)
 {
     Type     = type;
     Name     = DocumentationGenerator.GetCleanName(type);
     RawName  = type.Name;
     NiceName = DocumentationGenerator.GetNiceName(Name);
     Id       = DocumentationGenerator.GetTypeId(type);
     Filename = GetFilename(category);
     Link     = category.GetLink(type);
 }
Exemple #7
0
        private string GenerateField(FieldInfo field, DocumentationCategory category)
        {
            var type     = category.GetLink(field.FieldType);
            var niceName = DocumentationGenerator.GetNiceName(field.Name);

            return(category.Templates.Field
                   .Replace(_memberTypeTag, type)
                   .Replace(_memberNameTag, field.Name)
                   .Replace(_memberNiceNameTag, niceName));
        }
Exemple #8
0
        private string GenerateParameter(ParameterInfo parameter, DocumentationCategory category)
        {
            var decorator = parameter.ParameterType.IsByRef ? (parameter.IsOut ? _outDecorator : _refDecorator) : "";

            var decorators = GenerateDecorators(category, decorator);
            var type       = category.GetLink(parameter.ParameterType);

            return(category.Templates.Parameter
                   .Replace(_parameterDecoratorsTag, decorators)
                   .Replace(_parameterNameTag, parameter.Name)
                   .Replace(_parameterTypeTag, type));
        }
Exemple #9
0
 public string GenerateIndex(DocumentationCategory category)
 {
     return(category.Templates.Type
            .Replace(DocumentationGenerator.CategoryNameTag, category.Name)
            .Replace(DocumentationGenerator.CategoryNiceNameTag, category.NiceName)
            .Replace(DocumentationGenerator.CategoryIdTag, category.Id)
            .Replace(DocumentationGenerator.TypeNameTag, Name)
            .Replace(DocumentationGenerator.TypeRawNameTag, RawName)
            .Replace(DocumentationGenerator.TypeNiceNameTag, NiceName)
            .Replace(DocumentationGenerator.TypeIdTag, Id)
            .Replace(DocumentationGenerator.TypeFilenameTag, Filename));
 }
Exemple #10
0
        private string GenerateProperty(PropertyInfo property, DocumentationCategory category)
        {
            var method   = GetAbstractDecorator(property.GetMethod);
            var readOnly = !IsIncluded(property.SetMethod, IncludedAccessLevels) ? _readOnlyDecorator : "";

            var decorators = GenerateDecorators(category, readOnly, method);
            var type       = category.GetLink(property.PropertyType);

            return(category.Templates.Property
                   .Replace(_memberDecoratorsTag, decorators)
                   .Replace(_memberTypeTag, type)
                   .Replace(_memberNameTag, property.Name));
        }
Exemple #11
0
        private string GenerateMethod(MethodInfo method, DocumentationCategory category)
        {
            var decorator = GetAbstractDecorator(method);

            var decorators = GenerateDecorators(category, decorator);
            var type       = category.GetLink(method.ReturnType);
            var generics   = GenerateGenerics(method.GetGenericArguments(), category);
            var parameters = GenerateParameters(method.GetParameters(), category);

            return(category.Templates.Method
                   .Replace(_memberDecoratorsTag, decorators)
                   .Replace(_memberTypeTag, type)
                   .Replace(_memberNameTag, method.Name + generics)
                   .Replace(_memberParametersTag, parameters));
        }
Exemple #12
0
        private string GetTypeLink(Type type, DocumentationCategory category, string template)
        {
            var cleanName = DocumentationGenerator.GetCleanName(type);
            var niceName  = DocumentationGenerator.GetNiceName(cleanName);
            var id        = DocumentationGenerator.GetTypeId(type);

            return(template
                   .Replace(DocumentationGenerator.CategoryNameTag, category?.Name)
                   .Replace(DocumentationGenerator.CategoryNiceNameTag, category?.NiceName)
                   .Replace(DocumentationGenerator.CategoryIdTag, category?.Id)
                   .Replace(DocumentationGenerator.TypeIdTag, id)
                   .Replace(DocumentationGenerator.TypeNameTag, cleanName)
                   .Replace(DocumentationGenerator.TypeRawNameTag, type.Name)
                   .Replace(DocumentationGenerator.TypeNiceNameTag, niceName)
                   .Replace(DocumentationGenerator.TypeNamespaceTag, type.Namespace)
                   .Replace('`', '-'));             // this is specific to msdn but potentially makes sense for other scenarios as well
        }
Exemple #13
0
        private string GenerateValues(DocumentationType type, DocumentationCategory category)
        {
            var binding = GetBindingFlags();
            var builder = new StringBuilder();

            if (IncludedMemberTypes.HasFlag(MemberType.EnumValue))
            {
                var values = type.Type.GetFields(binding);

                if (values.Length > 0)
                {
                    var content = GetMembers(values, GenerateField, category, category.Templates.MemberSeparator);
                    builder.Append(content);
                }
            }

            return(builder.ToString());
        }
Exemple #14
0
        public string GenerateFile(DocumentationCategory category)
        {
            var generics = GenerateGenerics(category);
            var bases    = GenerateBases(category);
            var sections = GenerateSections(category);

            return(category.Templates.TypeFile
                   .Replace(DocumentationGenerator.CategoryNameTag, category.Name)
                   .Replace(DocumentationGenerator.CategoryNiceNameTag, category.NiceName)
                   .Replace(DocumentationGenerator.CategoryIdTag, category.Id)
                   .Replace(DocumentationGenerator.TypeIdTag, Id)
                   .Replace(DocumentationGenerator.TypeNameTag, Name)
                   .Replace(DocumentationGenerator.TypeRawNameTag, RawName)
                   .Replace(DocumentationGenerator.TypeNiceNameTag, NiceName)
                   .Replace(DocumentationGenerator.TypeNamespaceTag, Type.Namespace)
                   .Replace(DocumentationGenerator.TypeFilenameTag, Filename)
                   .Replace(_genericsTag, generics)
                   .Replace(_basesTag, bases)
                   .Replace(_sectionsTag, sections));
        }
Exemple #15
0
        public string Generate(DocumentationType type, DocumentationCategory category)
        {
            var niceName = DocumentationGenerator.GetNiceName(Name);
            var id       = DocumentationGenerator.GetId(Name);

            var members = type.Type.IsEnum
                                ? GenerateValues(type, category)
                                : GenerateMembers(type, category);

            return(!string.IsNullOrEmpty(members)
                                ? category.Templates.Section
                   .Replace(DocumentationGenerator.SectionNameTag, Name)
                   .Replace(DocumentationGenerator.SectionNiceNameTag, niceName)
                   .Replace(DocumentationGenerator.SectionIdTag, id)
                   .Replace(DocumentationGenerator.TypeIdTag, type.Id)
                   .Replace(DocumentationGenerator.TypeIdTag, type.Name)
                   .Replace(DocumentationGenerator.TypeIdTag, type.NiceName)
                   .Replace(_membersTag, members)
                                : "");
        }
Exemple #16
0
        private string GenerateSections(DocumentationCategory category)
        {
            var builder = new StringBuilder();
            var first   = true;

            foreach (var section in category.Sections)
            {
                var contents = section.Generate(this, category);

                if (!string.IsNullOrEmpty(contents))
                {
                    if (!first)
                    {
                        builder.Append(category.Templates.SectionSeparator);
                    }

                    builder.Append(contents);
                    first = false;
                }
            }

            return(builder.ToString());
        }
Exemple #17
0
        private string GetMembers <T>(T[] members, Func <T, DocumentationCategory, string> generator, DocumentationCategory category, string separator)
        {
            var builder = new StringBuilder();

            if (members.Length > 0)
            {
                for (var i = 0; i < members.Length; i++)
                {
                    if (i != 0)
                    {
                        builder.Append(separator);
                    }

                    var member = generator(members[i], category);
                    builder.Append(member);
                }
            }

            return(builder.ToString());
        }
Exemple #18
0
 private string GenerateGenerics(DocumentationCategory category)
 {
     return(Type.IsGenericType
                         ? category.GetGenerics(Type)
                         : "");
 }
Exemple #19
0
        private string GenerateDecorators(DocumentationCategory category, params string[] decorators)
        {
            var filtered = decorators.Where(decorator => !string.IsNullOrEmpty(decorator)).ToArray();

            return(GetMembers(filtered, GenerateDecorator, category, category.Templates.DecoratorSeparator));
        }
Exemple #20
0
 private string GenerateDecorator(string decorator, DocumentationCategory category)
 {
     return(category.Templates.Decorator
            .Replace(_decoratorNameTag, decorator));
 }
Exemple #21
0
 private string GenerateParameters(ParameterInfo[] parameters, DocumentationCategory category)
 {
     return(GetMembers(parameters, GenerateParameter, category, category.Templates.ParameterSeparator));
 }
Exemple #22
0
        private string GenerateMembers(DocumentationType type, DocumentationCategory category)
        {
            var binding = GetBindingFlags();
            var builder = new StringBuilder();
            var first   = true;

            if (IncludedMemberTypes.HasFlag(MemberType.Constructor))
            {
                var constructors = type.Type.GetConstructors(binding)
                                   .Where(constructor => IsIncluded(constructor, IncludedAccessLevels))
                                   .ToArray();

                if (constructors.Length > 0)
                {
                    var content = GetMembers(constructors, GenerateConstructor, category, category.Templates.MemberSeparator);
                    builder.Append(content);
                    first = false;
                }
            }

            if (IncludedMemberTypes.HasFlag(MemberType.Field))
            {
                var fields = type.Type.GetFields(binding)
                             .Where(field => IsIncluded(field, IncludedAccessLevels))
                             .ToArray();

                if (fields.Length > 0)
                {
                    var content = GetMembers(fields, GenerateField, category, category.Templates.MemberSeparator);

                    if (!first)
                    {
                        builder.Append(category.Templates.MemberSeparator);
                    }
                    builder.Append(content);
                    first = false;
                }
            }

            if (IncludedMemberTypes.HasFlag(MemberType.Property))
            {
                // setter access is determined later and specified via a read only decorator - set only is not supported

                var properties = type.Type.GetProperties(binding)
                                 .Where(property => IsIncluded(property.GetMethod, IncludedAccessLevels))
                                 .ToArray();

                if (properties.Length > 0)
                {
                    var content = GetMembers(properties, GenerateProperty, category, category.Templates.MemberSeparator);

                    if (!first)
                    {
                        builder.Append(category.Templates.MemberSeparator);
                    }
                    builder.Append(content);
                    first = false;
                }
            }

            if (IncludedMemberTypes.HasFlag(MemberType.Method))
            {
                var methods = type.Type.GetMethods(binding)
                              .Where(method => IsIncluded(method, IncludedAccessLevels))
                              .Where(method => !_ignoredMethods.Contains(method.Name))
                              .Where(method => !method.IsSpecialName)
                              .ToArray();

                if (methods.Length > 0)
                {
                    var content = GetMembers(methods, GenerateMethod, category, category.Templates.MemberSeparator);

                    if (!first)
                    {
                        builder.Append(category.Templates.MemberSeparator);
                    }
                    builder.Append(content);
                    first = false;
                }
            }

            return(builder.ToString());
        }
Exemple #23
0
 private string GenerateGenericParameter(Type type, DocumentationCategory category)
 {
     return(category.GetLink(type));
 }