private static void ParseComments([NotNull] TransformationContext context, [NotNull] ModelContainer container) { Logger.Info("parsing comments"); var sources = context.Comments.GetSourcesWithComments(); var notFoundCounter = 0; foreach (var sourceSnapshot in sources) { var models = container.GetAll <Model>().Where(model => model.Comments.FullPath == sourceSnapshot.File.FullName && model.ModelType != ModelType.Module); var comments = context.Comments.GetAllComments(sourceSnapshot).ToList(); var results = new List <CommentBlock>(); results.AddRange(models.SelectMany(model => model.FindCommentsForMembers(context.Comments))); Logger.Trace("finding parent for orphaned comments"); var orphanedComments = comments .Where(comment => results.All(found => comment.Location != found.Location)) .Select(comment => new CommentWrapper(comment)) .ToArray(); Logger.Info($"total orphaned: {orphanedComments.Length} in {sourceSnapshot.File.FullName}"); var modules = container.GetAll <ModuleModel>().Where(model => model.Comments.FullPath == sourceSnapshot.File.FullName) .ToArray(); foreach (var notFoundComment in orphanedComments) { var targetModule = modules.FirstOrDefault(module => module.Name == notFoundComment.Comment.Location.Source.File.FullName); if (targetModule == null) { continue; } foreach (var member in targetModule.Items) { if (member.Comments.Location.HasValue && notFoundComment.Comment.Location.IntersectsWith(member.Comments.Location.Value)) { member.Comments.AddComments(notFoundComment.Comment); notFoundComment.WasFound = true; break; } } } var notFoundComments = orphanedComments.Where(comm => !comm.WasFound).ToArray(); Logger.Trace($"total not found: {notFoundComments.Length}"); notFoundCounter += notFoundComments.Length; foreach (var notFoundComment in notFoundComments) { Logger.Trace(notFoundComment.Comment.Location); } } Logger.Trace($"total not found: {notFoundCounter}"); Logger.Info($"finished parsing comments"); }