Esempio n. 1
0
        /// <summary>
        /// Create a new instance.
        /// </summary>
        /// <param name="type">The type information.</param>
        /// <param name="commentLookup">The XML comment of the type and the members.</param>
        /// <param name="context">The context that manages the state of the output process for class documents.</param>
        public TypeWithComment(Type type, ILookup <string, XmlComment>?commentLookup, ClassDocContext context)
        {
            Context         = context;
            m_CommentLookup = commentLookup;

            this.Info = type;

            GenericParameterTypes = CreateGenericParameters().AsReadOnly();
            Constructors          = CreateConstructors().AsReadOnly();
            Methods    = CreateMethodList().AsReadOnly();
            Properties = CreatePropertyList().AsReadOnly();
            Fields     = CreateFieldList().AsReadOnly();
            Events     = CreateEventList().AsReadOnly();

            if (commentLookup == null)
            {
                Comment = XmlComment.Empty;
            }
            else
            {
                string typeName = type.FullName.Replace('+', '.');
                Comment = commentLookup[typeName].Where(x => x.Kind == XmlCommentKind.Type && x.TypeName == typeName).FirstOrDefault() ?? XmlComment.Empty;
            }

            DelegateMethodInfo = CreateDelegateMethodInfo();
        }
        /// <summary>
        /// Create a new instance.
        /// </summary>
        /// <param name="member">The member information.</param>
        /// <param name="comment">The XML comment.</param>
        /// <param name="context">The context that manages the state of the output process for class documents.</param>
        protected MemberInfoWithComment(TInfo member, XmlComment comment, ClassDocContext context)
        {
            Context = context;

            Info    = member;
            Comment = comment ?? XmlComment.Empty;
        }
        /// <summary>
        /// Create a new instance.
        /// </summary>
        /// <param name="parameter">The parameter information.</param>
        /// <param name="commentGetter">The method to get comment of parameter.</param>
        /// <param name="context">The context that manages the state of the output process for class documents.</param>
        public ParameterInfoWithComment(ParameterInfo parameter, Func <ParameterComment> commentGetter, ClassDocContext context)
        {
            m_Context = context;

            Info = parameter;

            m_CommentGetter = commentGetter;
        }
Esempio n. 4
0
        /// <summary>
        /// Loads the types defined in the specified assembly.
        /// </summary>
        /// <param name="dllPath">The assembly file path.</param>
        /// <param name="context">The context that manages the state of the output process for class documents.</param>
        /// <param name="nameSpace">The namespace to load.</param>
        /// <returns>The type information.</returns>
        private static IEnumerable <TypeWithComment> EnumerateTypes(string dllPath, ClassDocContext context, string?nameSpace = null)
        {
            var xmlPath = Path.Combine(Directory.GetParent(dllPath).FullName, Path.GetFileNameWithoutExtension(dllPath) + ".xml");

            IEnumerable <XmlComment> comments = new XmlComment[0];

            if (File.Exists(xmlPath))
            {
                comments = XmlCommentReader.ReadXmlComments(XDocument.Parse(File.ReadAllText(xmlPath)), context, nameSpace);
            }

            var commentsLookup = comments.ToLookup(x => x.TypeName);

            // List<TypeWithComment> typeComments = new List<TypeWithComment>();

            Func <Type, bool> typeFilter;

            if (!string.IsNullOrEmpty(nameSpace))
            {
                typeFilter = type =>
                {
                    if (!type.Namespace.StartsWith(nameSpace))
                    {
                        return(false);
                    }
                    if (context.TypeFilter != null && !context.TypeFilter(type))
                    {
                        return(false);
                    }
                    return(true);
                };
            }
            else
            {
                typeFilter = context.TypeFilter;
            }

            foreach (var type in EnumerateTypes(Assembly.LoadFrom(dllPath), typeFilter))
            {
                var info = new TypeWithComment(type, commentsLookup, context);

                // typeComments.Add(info);

                context.StoreTypeInfo(info);

                yield return(info);
            }

            // return typeComments.AsReadOnly();
        }
Esempio n. 5
0
        /// <summary>
        /// Create a new instance.
        /// </summary>
        /// <param name="exceptionTypeSignature">The exception type signature.</param>
        /// <param name="descriptions">The descriptions.</param>
        /// <param name="context">The context that manages the state of the output process for class documents.</param>
        public ExceptionComment(string exceptionTypeSignature, string[] descriptions, ClassDocContext context)
        {
            Context = context;

            ExceptionTypeSignatureName = exceptionTypeSignature;
            Descriptions = descriptions;

            m_ExceptionType = null;

            if (XmlCommentSignature.TryParse(exceptionTypeSignature, out var signature))
            {
                if (TypeLoader.TryGetType(signature.TypeName, out Type? type))
                {
                    m_ExceptionType = type;
                }
            }

            ExceptionTypeSignature = signature;
        }
 /// <summary>
 /// Create a new instance.
 /// </summary>
 /// <param name="prop">The property information.</param>
 /// <param name="comment">The XML comment.</param>
 /// <param name="context">The context that manages the state of the output process for class documents.</param>
 public PropertyInfoWithComment(PropertyInfo prop, XmlComment comment, ClassDocContext context) : base(prop, comment, context)
 {
     Parameters = CreateParameterList(Info.GetIndexParameters());
 }
Esempio n. 7
0
 /// <summary>
 /// Create a new instance.
 /// </summary>
 /// <param name="context">The context that manages the state of the output process for class documents.</param>
 public XmlComment(ClassDocContext context)
 {
     Context = context;
 }
Esempio n. 8
0
 /// <summary>
 /// Create a new instance.
 /// </summary>
 /// <param name="method">The method information.</param>
 /// <param name="comment">The XML comment.</param>
 /// <param name="context">The context that manages the state of the output process for class documents.</param>
 public MethodInfoWithComment(MethodInfo method, XmlComment comment, ClassDocContext context) : base(method, comment, context)
 {
     Parameters            = CreateParameterList(method.GetParameters());
     GenericParameterTypes = CreateGenericParameters().AsReadOnly();
 }
Esempio n. 9
0
 internal ParameterComment(string name, ClassDocContext context)
 {
     Context      = context;
     Name         = name;
     Descriptions = EmptyStringArray;
 }
Esempio n. 10
0
 /// <summary>
 /// Create a new instance.
 /// </summary>
 /// <param name="name">The parameter name.</param>
 /// <param name="descriptions">The descriptions.</param>
 /// <param name="context">The context that manages the state of the output process for class documents.</param>
 public ParameterComment(string name, string[] descriptions, ClassDocContext context)
 {
     Context      = context;
     Name         = name;
     Descriptions = descriptions ?? EmptyStringArray;
 }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="ctor">The constructor information.</param>
 /// <param name="comment">The XML comment.</param>
 /// <param name="context">The context that manages the state of the output process for class documents.</param>
 public ConstructorInfoWithComment(ConstructorInfo ctor, XmlComment comment, ClassDocContext context) : base(ctor, comment, context)
 {
     Parameters = CreateParameterList(ctor.GetParameters());
 }
Esempio n. 12
0
        /// <summary>
        /// Reads XML comments from the specified XML document.
        /// </summary>
        /// <param name="xDocument">The XML document.</param>
        /// <param name="context">The context that manages the state of the output process for class documents.</param>
        /// <param name="nameSpace">The namespace to read.</param>
        /// <returns>An Enumerator.</returns>
        internal static IEnumerable <XmlComment> ReadXmlComments(XDocument xDocument, ClassDocContext context, string?nameSpace = null)
        {
            string assemblyName = xDocument.Descendants("assembly").First().Elements("name").First().Value;

            IEnumerable <XmlComment?> documents = xDocument.Descendants("member")

                                                  .Select(x =>
            {
                // signature

                string signatureName = x.Attribute("name").Value;

                if (!XmlCommentSignature.TryParse(signatureName, out XmlCommentSignature signature))
                {
                    return(null);
                }

                string summary = FormatTextElement(x.Elements("summary"));
                string returns = FormatTextElement(x.Elements("returns"));
                string remarks = FormatTextElement(x.Elements("remarks"));

                // paeameter

                var parameters = x.Elements("param")
                                 .Select(element => (name: element.Attribute("name").Value, content: FormatTextElement(element)))
                                 .GroupBy(comment => comment.name)
                                 .ToDictionary(group => group.Key, g => new ParameterComment(g.Key, g.Select(v => v.content).ToArray(), context))
                ;

                // type parameter

                var typeParameters = x.Elements("typeparam")
                                     .Select(element => (name: element.Attribute("name").Value, content: FormatTextElement(element)))
                                     .GroupBy(comment => comment.name)
                                     .ToDictionary(group => group.Key, g => new ParameterComment(g.Key, g.Select(v => v.content).ToArray(), context))
                ;

                // exception

                var exceptions = x.Elements("exception")
                                 .Select(e => (name: e.Attribute("cref").Value, content: FormatTextElement(e)))
                                 .GroupBy(comment => comment.name)
                                 .ToDictionary(group => group.Key, g => new ExceptionComment(g.Key, g.Select(v => v.content).ToArray(), context))
                                 .Values.ToArray();

                // inheritdoc

                bool inheritdoc = x.Element("inheritdoc") != null;

                return(new XmlComment(context)
                {
                    SignatureName = signatureName,
                    IsInherit = inheritdoc,
                    Signature = signature,
                    Summary = summary.Trim(),
                    Remarks = remarks.Trim(),
                    ParametersInternal = parameters,
                    TypeParametersInternal = typeParameters,
                    Returns = returns.Trim(),
                    ExceptionsInternal = exceptions,
                });
            });

            foreach (var doc in documents)
            {
                if (doc == null)
                {
                    continue;
                }

                if (!string.IsNullOrWhiteSpace(nameSpace) && !doc.TypeName.StartsWith(nameSpace))
                {
                    continue;
                }

                // System.Diagnostics.Debug.WriteLine(doc.SignatureName);

                yield return(doc);
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Create a new instance.
 /// </summary>
 /// <param name="field">The field information.</param>
 /// <param name="comment">The XML comment.</param>
 /// <param name="context">The context that manages the state of the output process for class documents.</param>
 public FieldInfoWithComment(FieldInfo field, XmlComment comment, ClassDocContext context) : base(field, comment, context)
 {
 }
Esempio n. 14
0
 /// <summary>
 /// Create a new instance.
 /// </summary>
 /// <param name="evt">The field information.</param>
 /// <param name="comment">The XML comment.</param>
 /// <param name="context">The context that manages the state of the output process for class documents.</param>
 public EventInfoWithComment(EventInfo evt, XmlComment comment, ClassDocContext context) : base(evt, comment, context)
 {
 }
Esempio n. 15
0
        /// <summary>
        /// Loads the types defined in the specified assemblies.
        /// </summary>
        /// <param name="dllPaths">The assembly file path.</param>
        /// <param name="context">The context that manages the state of the output process for class documents.</param>
        /// <param name="nameSpace">The namespace to load.</param>
        /// <returns>The type information.</returns>
        public static IReadOnlyList <TypeWithComment> LoadTypes(IEnumerable <string> dllPaths, ClassDocContext context, string?nameSpace = null)
        {
            List <TypeWithComment> types = new List <TypeWithComment>();

            foreach (var dllPath in dllPaths)
            {
                foreach (var type in EnumerateTypes(dllPath, context, nameSpace))
                {
                    types.Add(type);
                }
            }

            return(types.AsReadOnly());
        }
Esempio n. 16
0
 /// <summary>
 /// Loads the types defined in the specified assembly.
 /// </summary>
 /// <param name="dllPath">The assembly file path.</param>
 /// <param name="context">The context that manages the state of the output process for class documents.</param>
 /// <param name="nameSpace">The namespace to load.</param>
 /// <returns>The type information.</returns>
 public static IReadOnlyList <TypeWithComment> LoadTypes(string dllPath, ClassDocContext context, string?nameSpace = null)
 {
     return(EnumerateTypes(dllPath, context, nameSpace).ToArray());
 }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="parameterType">The generic parameter type.</param>
 /// <param name="commentGetter">The method to get comment of parameter.</param>
 /// <param name="context">The context that manages the state of the output process for class documents.</param>
 public TypeParameterWithComment(Type parameterType, Func <ParameterComment> commentGetter, ClassDocContext context)
 {
     ParameterType   = parameterType;
     Context         = context;
     m_CommentGetter = commentGetter;
 }