Пример #1
0
 public static TripleSlashCommentModel CreateModel(string xml, SyntaxLanguage language, ITripleSlashCommentParserContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (string.IsNullOrEmpty(xml))
     {
         return(null);
     }
     // Quick turnaround for badly formed XML comment
     if (xml.StartsWith("<!-- Badly formed XML comment ignored for member "))
     {
         Logger.LogWarning($"Invalid triple slash comment is ignored: {xml}");
         return(null);
     }
     try
     {
         var model = new TripleSlashCommentModel(xml, language, context);
         return(model);
     }
     catch (XmlException)
     {
         return(null);
     }
 }
Пример #2
0
        public void CopyInheritedData(TripleSlashCommentModel src)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }

            Summary = Summary ?? src.Summary;
            Remarks = Remarks ?? src.Remarks;
            Returns = Returns ?? src.Returns;
            if (Exceptions == null && src.Exceptions != null)
            {
                Exceptions = src.Exceptions.Select(e => e.Clone()).ToList();
            }
            if (Sees == null && src.Sees != null)
            {
                Sees = src.Sees.Select(s => s.Clone()).ToList();
            }
            if (SeeAlsos == null && src.SeeAlsos != null)
            {
                SeeAlsos = src.SeeAlsos.Select(s => s.Clone()).ToList();
            }
            if (Examples == null && src.Examples != null)
            {
                Examples = new List <string>(src.Examples);
            }
            if (Parameters == null && src.Parameters != null)
            {
                Parameters = new Dictionary <string, string>(src.Parameters);
            }
            if (TypeParameters == null && src.TypeParameters != null)
            {
                TypeParameters = new Dictionary <string, string>(src.TypeParameters);
            }
        }
Пример #3
0
 public static void FeedComments(MetadataItem item, ITripleSlashCommentParserContext context)
 {
     if (!string.IsNullOrEmpty(item.RawComment))
     {
         var commentModel = TripleSlashCommentModel.CreateModel(item.RawComment, item.Language, context);
         if (commentModel == null)
         {
             return;
         }
         item.Summary      = commentModel.Summary;
         item.Remarks      = commentModel.Remarks;
         item.Exceptions   = commentModel.Exceptions;
         item.Sees         = commentModel.Sees;
         item.SeeAlsos     = commentModel.SeeAlsos;
         item.Examples     = commentModel.Examples;
         item.CommentModel = commentModel;
     }
 }
Пример #4
0
 public static TripleSlashCommentModel CreateModel(string xml, SyntaxLanguage language, ITripleSlashCommentParserContext context)
 {
     if (context == null) throw new ArgumentNullException(nameof(context));
     if (string.IsNullOrEmpty(xml)) return null;
     // Quick turnaround for badly formed XML comment
     if (xml.StartsWith("<!-- Badly formed XML comment ignored for member "))
     {
         Logger.LogWarning($"Invalid triple slash comment is ignored: {xml}");
         return null;
     }
     try
     {
         var model = new TripleSlashCommentModel(xml, language, context);
         return model;
     }
     catch (XmlException)
     {
         return null;
     }
 }
Пример #5
0
        private static void PatchViewModel(MetadataItem item, string comment)
        {
            var context = new TripleSlashCommentParserContext
            {
                AddReferenceDelegate = (s, e) => { }
            };
            var commentModel = TripleSlashCommentModel.CreateModel(comment, SyntaxLanguage.CSharp, context);
            var summary      = commentModel.Summary;

            if (!string.IsNullOrEmpty(summary))
            {
                item.Summary = summary;
            }
            var remarks = commentModel.Remarks;

            if (!string.IsNullOrEmpty(remarks))
            {
                item.Remarks = remarks;
            }
            var exceptions = commentModel.Exceptions;

            if (exceptions != null && exceptions.Count > 0)
            {
                item.Exceptions = exceptions;
            }
            var sees = commentModel.Sees;

            if (sees != null && sees.Count > 0)
            {
                item.Sees = sees;
            }
            var seeAlsos = commentModel.SeeAlsos;

            if (seeAlsos != null && seeAlsos.Count > 0)
            {
                item.SeeAlsos = seeAlsos;
            }
            var examples = commentModel.Examples;

            if (examples != null && examples.Count > 0)
            {
                item.Examples = examples;
            }
            if (item.Syntax != null)
            {
                if (item.Syntax.Parameters != null)
                {
                    foreach (var p in item.Syntax.Parameters)
                    {
                        var description = commentModel.GetParameter(p.Name);
                        if (!string.IsNullOrEmpty(description))
                        {
                            p.Description = description;
                        }
                    }
                }
                if (item.Syntax.TypeParameters != null)
                {
                    foreach (var p in item.Syntax.TypeParameters)
                    {
                        var description = commentModel.GetTypeParameter(p.Name);
                        if (!string.IsNullOrEmpty(description))
                        {
                            p.Description = description;
                        }
                    }
                }
                if (item.Syntax.Return != null)
                {
                    var returns = commentModel.Returns;
                    if (!string.IsNullOrEmpty(returns))
                    {
                        item.Syntax.Return.Description = returns;
                    }
                }
            }
            // todo more.
        }