Example #1
0
        public List <MarkDownType> GetTypes(Assembly assembly)
        {
            var list = new List <MarkDownType>();

            ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((assembly == null),
                                                                                nameof(assembly));

            if (assembly == null)
            {
                return(list);
            }

            var typeArray = assembly.GetTypes();

            foreach (var type in typeArray)
            {
                if (type.CustomAttributes != null && type.CheckAttribute <Documented>())
                {
                    var entity = MarkDownEntityCreator.CreateType(type, !type.IsEnum);

                    entity.Properties.AddRange(ReflectValidator.GetProperties(type, entity));
                    entity.Fields.AddRange(ReflectValidator.GetFields(type, entity));
                    entity.Methods.AddRange(ReflectValidator.GetMethods(type, entity));

                    list.Add(entity);
                }
            }
            return(list);
        }
Example #2
0
        public MarkDownBuilder(IMdGenerator markDownGenerator, IXmlVsParser xmlVsParser)
        {
            ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((markDownGenerator == null),
                                                                                nameof(markDownGenerator));
            ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((xmlVsParser == null),
                                                                                nameof(xmlVsParser));

            _markDownGenerator = markDownGenerator;
            _xmlVsParser       = xmlVsParser;
        }
 public MdFluentBuilder(string template, string fileName, MarkDownType type)
 {
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((string.IsNullOrWhiteSpace(template)),
                                                                         nameof(template));
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((string.IsNullOrWhiteSpace(fileName)),
                                                                         nameof(fileName));
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((type == null),
                                                                         nameof(type));
     Template = template;
     FileName = fileName;
     Type     = type;
 }
Example #4
0
 public void Build(string template)
 {
     ConditionValidator.ThrowSystemExceptionIfNotValid <OperationCanceledException>(Types == null,
                                                                                    $"Should be run 'Load' method");
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((string.IsNullOrWhiteSpace(template)),
                                                                         nameof(template));
     _content = new List <IMdStringEditor>();
     foreach (var type in Types)
     {
         var mb = new MdFluentBuilder(template, type.Name, type);
         _content.Add(mb.Build());
     }
 }
Example #5
0
 public List <MarkDownType> UpdateComments(List <MarkDownType> types, XmlVsComment[] comments)
 {
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((types == null), nameof(types));
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((comments == null), nameof(comments));
     foreach (var markDownType in types)
     {
         markDownType.Summary = comments.FirstOrDefault(s => s.FullMemberName == markDownType.FullMemberName)
                                ?.Summary;
         markDownType.Properties.FillSummary(comments);
         markDownType.Fields.FillSummary(comments);
         markDownType.Methods.FillSummary(comments);
     }
     return(types);
 }
Example #6
0
        /// <summary>
        /// Get from repository https://github.com/neuecc/MarkdownGenerator/blob/master/VSDocParser.cs
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        private XmlVsComment[] ParseXmlComment(XDocument document)
        {
            ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((document == null), nameof(document));

            return(document.Descendants("member")
                   .Select(x =>
            {
                var match = Regex.Match(x.Attribute("name").Value, @"(.):(.+)\.([^.()]+)?(\(.+\)|$)");
                if (!match.Groups[1].Success)
                {
                    return null;
                }

                var memberType = (MemberType)match.Groups[1].Value[0];
                if (memberType == MemberType.None)
                {
                    return null;
                }

                var summary = ((string)x.Element("summary")) ?? "";
                if (summary != "")
                {
                    summary = string.Join("  ", summary.Split(new[] { "\r", "\n", "\t" }, StringSplitOptions.RemoveEmptyEntries).Select(y => y.Trim()));
                }

                var returns = ((string)x.Element("returns")) ?? "";
                var remarks = ((string)x.Element("remarks")) ?? "";
                var parameters = x.Elements("param")
                                 .Select(e => Tuple.Create(e.Attribute("name").Value, e))
                                 .Distinct(new ItemEqualityComparer <string, XElement>())
                                 .ToDictionary(e => e.Item1, e => e.Item2.Value);

                var className = (memberType == MemberType.Type)
                        ? match.Groups[2].Value + "." + match.Groups[3].Value
                        : match.Groups[2].Value;

                return new XmlVsComment
                {
                    MemberType = memberType,
                    ClassName = className,
                    MemberName = match.Groups[3].Value,
                    Summary = summary.Trim(),
                    Remarks = remarks.Trim(),
                    Parameters = parameters,
                    Returns = returns.Trim()
                };
            })
                   .Where(x => x != null)
                   .ToArray());
        }
Example #7
0
        public void Load(string dllPath, string dllXmlPath)
        {
            ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((string.IsNullOrWhiteSpace(dllPath)),
                                                                                nameof(dllPath));
            ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((string.IsNullOrWhiteSpace(dllXmlPath)),
                                                                                nameof(dllXmlPath));

            _content = new List <IMdStringEditor>();

            var assembly = Assembly.LoadFile(dllPath);
            var types    = _markDownGenerator.GetTypes(assembly);
            var comments = _xmlVsParser.GetComments(dllXmlPath);

            Types = _markDownGenerator.UpdateComments(types, comments);
        }
Example #8
0
        /// <summary>
        /// Get description attribute value
        /// </summary>
        /// <param name="enumerationValue"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static string ToDescription <T>(this T enumerationValue)
            where T : struct
        {
            var type = enumerationValue.GetType();

            ConditionValidator.ThrowExceptionIfNotValid <ArgumentException>((!type.IsEnum),
                                                                            $"EnumerationValue must be of Enum type {enumerationValue}");
            var memberInfo = type.GetMember(enumerationValue.ToString());

            if (memberInfo.Length <= 0)
            {
                return(enumerationValue.ToString());
            }
            var attrs = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);

            return(attrs.Length > 0 ? ((DescriptionAttribute)attrs[0]).Description : enumerationValue.ToString());
        }
 public void ConditionValidator_Should_ReturnArgumentNullException_With_Message()
 {
     //act
     Assert.Throws(typeof(ArgumentNullException),
                   () => ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((true), "name", "string"));
 }
 public void ConditionValidator_WhenFalseCondition_Should_ReturnArgumentOutOfRangeException_With_Message()
 {
     //act
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentOutOfRangeException>((false), "name", "string");
 }
 public void ConditionValidator_Should_ReturnArgumentOutOfRangeException()
 {
     //act
     Assert.Throws(typeof(ArgumentOutOfRangeException),
                   () => ConditionValidator.ThrowExceptionIfNotValid <ArgumentOutOfRangeException>((true), "name"));
 }
Example #12
0
 public MdStringEditor(string fileName)
 {
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((string.IsNullOrWhiteSpace(fileName)),
                                                                         nameof(fileName));
     FileName = fileName;
 }
Example #13
0
 private XDocument GetLoadFile(string path)
 {
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((!File.Exists(path)),
                                                                         nameof(path), $"Path '{path}' does not exist");
     return(XDocument.Load(path));
 }
Example #14
0
 public XmlVsComment[] GetComments(string path)
 {
     ConditionValidator.ThrowExceptionIfNotValid <ArgumentNullException>((string.IsNullOrWhiteSpace(path)),
                                                                         nameof(path));
     return(ParseXmlComment(GetLoadFile(path)));
 }