public static List <CommentBlock> SearchComments( [NotNull] CommentBag commentBag, [CanBeNull] CommentBlockModel comments) { var results = new List <CommentBlock>(); if (comments != null) { if (comments.Location.HasValue) { var before = commentBag.TryFindBefore(comments.Location.Value); var after = commentBag.TryFindAfter(comments.Location.Value); if (before != null) { // this comment is on the same line. it's probably for current model var trimmedStart = before.GetText().TrimStart(' ').Substring(0, 5); var nIndex = trimmedStart.IndexOf("\n", StringComparison.Ordinal); if (nIndex >= 0 || before.Location.StartPos == 0) { results.Add(before); comments.AddComments(before); } } if (after != null) { var trimmedStart = after.GetText().TrimStart(' ').Substring(0, 5); var nIndex = trimmedStart.IndexOf("\n", StringComparison.Ordinal); // this comment is on the same line. it's probably for current model if (nIndex < 0) { results.Add(after); comments.AddComments(after); } } } } return(results); }