Ejemplo n.º 1
0
        // Public Methods (3) 

        /// <summary>
        /// Returns the documentation for a <see cref="Type" />.
        /// </summary>
        /// <param name="type">The CLR type.</param>
        /// <param name="ignoreXmlDocErrors">
        /// Ignore errors while loading XML documentation for <paramref name="type" /> or (re-)throw exception(s).
        /// </param>
        /// <returns>
        /// The document for <paramref name="type" /> or <see langword="null" />
        /// if <paramref name="type" /> is also <see langword="null" />.
        /// </returns>
        public static TypeDocumentation GetDocumentation(Type type,
                                                         bool ignoreXmlDocErrors = true)
        {
            if (type == null)
            {
                return(null);
            }

            var asm = type.Assembly;

            if (asm == null)
            {
                return(null);
            }

            var asmDoc = AssemblyDocumentation.FromAssembly(asm,
                                                            ignoreXmlDocErrors: ignoreXmlDocErrors,
                                                            useCache: true);

            var result = asmDoc.GetTypes()
                         .FirstOrDefault(t => TypeHelper.GetFullName(t.ClrType) == TypeHelper.GetFullName(type));

            if (result == null)
            {
                result = new TypeDocumentation(asmDoc, type,
                                               xml: null);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public IDictionary <string, TypeDocumentation> GetModelDocumentation(HttpActionDescriptor actionDescriptor)
        {
            var retDictionary = new Dictionary <string, TypeDocumentation>();
            ReflectedHttpActionDescriptor reflectedActionDescriptor = actionDescriptor as ReflectedHttpActionDescriptor;

            if (reflectedActionDescriptor != null)
            {
                foreach (var parameterDescriptor in reflectedActionDescriptor.GetParameters())
                {
                    var paramType = parameterDescriptor.ParameterType;
                    //if (!(paramType == typeof(QuizRequest)))
                    //    continue;

                    if (!paramType.IsValueType)
                    {
                        TypeDocumentation typeDocs = new TypeDocumentation();


                        string selectExpression = String.Format(CultureInfo.InvariantCulture, TypeExpression, GetTypeName(paramType));
                        var    typeNode         = _documentNavigator.SelectSingleNode(selectExpression);

                        if (typeNode != null)
                        {
                            XPathNavigator summaryNode;
                            summaryNode = typeNode.SelectSingleNode("summary");
                            if (summaryNode != null)
                            {
                                typeDocs.Summary = summaryNode.Value;
                            }
                        }


                        foreach (var prop in paramType.GetProperties())
                        {
                            string propName       = prop.Name;
                            string propDocs       = string.Empty;
                            string propExpression = String.Format(CultureInfo.InvariantCulture, PropertyExpression, GetPropertyName(prop));
                            var    propNode       = _documentNavigator.SelectSingleNode(propExpression);
                            if (propNode != null)
                            {
                                XPathNavigator summaryNode;
                                summaryNode = propNode.SelectSingleNode("summary");
                                if (summaryNode != null)
                                {
                                    propDocs = summaryNode.Value;
                                }
                            }
                            typeDocs.PropertyDocumentation.Add(new PropertyDocumentation(propName, prop.PropertyType.Name, propDocs));
                        }
                        retDictionary.Add(parameterDescriptor.ParameterName, typeDocs);
                    }
                }
            }

            return(retDictionary);
        }
Ejemplo n.º 3
0
        public TypeDocumentationMarkdownWriter(IAssemblyDocumentationReader assemblyDocumentationReader, Type type)
        {
            if (assemblyDocumentationReader == null)
            {
                throw new ArgumentNullException(nameof(assemblyDocumentationReader));
            }

            _assemblyDocumentationReader = assemblyDocumentationReader;
            _type = type;
            _typeDocumentation = assemblyDocumentationReader.GetDocumentationOf(type);
            _subWriters        = new List <IMarkdownWriter>();
        }
Ejemplo n.º 4
0
        private void AddTables(TypeDocumentation type, MDDocument md)
        {
            var path = $"{this.rootName}/{type.FullName.Replace(".", "/")}";

            this.AddTable("Constructors", $"{path}/Constructors", type.ConstructorDocumentations, md);

            this.AddTable("Properties", $"{path}/Properties", type.PropertyDocumentations, md);

            this.AddTable("Methods", $"{path}/Methods", type.MethodDocumentations, md);

            this.AddTable("Fields", $"{path}/Fields", type.FieldDocumentations, md);
        }
Ejemplo n.º 5
0
        protected string GetTypeDirRelative(TypeDocumentation type)
        {
            var dirName = type.TypeId.Name;

            if (type.TypeId is GenericTypeInstanceId genericTypeInstance)
            {
                dirName += "-" + genericTypeInstance.TypeArguments.Count;
            }
            else if (type.TypeId is GenericTypeId genericType)
            {
                dirName += "-" + genericType.Arity;
            }

            if (type.IsNestedType)
            {
                return(Path.Combine(GetTypeDirRelative(type.DeclaringType !), dirName));
            }
            else
            {
                return(Path.Combine(GetNamespaceDirRelative(type.NamespaceDocumentation), dirName));
            }
        }
        /// <summary>
        /// </summary>
        protected override void OnParametersSet()
        {
            base.OnParametersSet();

            this.Documentation = this.Parser.GetDocumentation(this.TypeName);
        }
Ejemplo n.º 7
0
 public PropertyDocBuilder(PropertyDocumentation propertyDocumentation, TypeDocumentation typeDocumentation, AssemblyDocumentation assemblyDocumentation)
     : base(propertyDocumentation, typeDocumentation, assemblyDocumentation)
 {
 }
Ejemplo n.º 8
0
 public MethodDocBuilder(MethodDocumentation methodDocumentation, TypeDocumentation typeDocumentation, AssemblyDocumentation assemblyDocumentation)
     : base(methodDocumentation, typeDocumentation, assemblyDocumentation)
 {
 }
Ejemplo n.º 9
0
 public TypeDocBuilder(TypeDocumentation typeDocumentation, AssemblyDocumentation assemblyDocumentation, string rootName)
     : base(typeDocumentation, typeDocumentation, assemblyDocumentation)
 {
     this.rootName = rootName;
 }
Ejemplo n.º 10
0
 protected override OverloadDocumentation GetOverloadDocumentationInstance(TypeDocumentation typeDocumentation)
 {
     return(typeDocumentation.Operators.First().Overloads.First());
 }
Ejemplo n.º 11
0
        private async Task GenerateDocsAsync <TBuilder>(IEnumerable <DocumentationBase> documentations, TypeDocumentation typeDocumentation, AssemblyDocumentation assemblyDocumentation, DirectoryInfo typeDir, string dirName)
            where TBuilder : DocBuilder
        {
            var docDir = Directory.CreateDirectory(Path.Combine(typeDir.FullName, dirName));

            foreach (var documentation in documentations)
            {
                try
                {
                    var docBuilder = (TBuilder)Activator.CreateInstance(typeof(TBuilder), documentation, typeDocumentation, assemblyDocumentation);
                    using (var stream = File.CreateText(Path.Combine(docDir.FullName, $"{documentation.GetSafeName()}.md")))
                    {
                        await stream.WriteAsync(docBuilder.Generate());

                        await stream.FlushAsync();
                    }
                }
                catch (System.IO.IOException)
                {
                    // Failure to write.
                }
            }
        }
Ejemplo n.º 12
0
 protected abstract OverloadDocumentation GetOverloadDocumentationInstance(TypeDocumentation typeDocumentation);
Ejemplo n.º 13
0
 protected override MemberDocumentation GetMemberDocumentationInstance(TypeDocumentation typeDocumentation)
 {
     return(typeDocumentation.Operators.First());
 }
Ejemplo n.º 14
0
 public FieldDocBuilder(FieldDocumentation fieldDocumentation, TypeDocumentation typeDocumentation, AssemblyDocumentation assemblyDocumentation)
     : base(fieldDocumentation, typeDocumentation, assemblyDocumentation)
 {
 }
Ejemplo n.º 15
0
 public DocBuilder(DocumentationBase documentation, TypeDocumentation typeDocumentation, AssemblyDocumentation assemblyDocumentation)
 {
     this.AssemblyDocumentation = assemblyDocumentation;
     this.Documentation         = documentation;
     this.TypeDocumentation     = typeDocumentation;
 }
Ejemplo n.º 16
0
 protected override MemberDocumentation GetMemberDocumentationInstance(TypeDocumentation typeDocumentation)
 {
     return(typeDocumentation.Constructors !);
 }
Ejemplo n.º 17
0
 protected override MemberDocumentation GetMemberDocumentationInstance(TypeDocumentation typeDocumentation)
 {
     return(typeDocumentation.Fields.Single());
 }
Ejemplo n.º 18
0
 protected abstract MemberDocumentation GetMemberDocumentationInstance(TypeDocumentation typeDocumentation);