Commenter.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using ICSharpCode.NRefactory.CSharp;
  4. namespace SharpieBinder
  5. {
  6. public static class Commenter
  7. {
  8. /// <summary>
  9. /// Inserts comments with "summary" tag over ast node. multiline.
  10. /// </summary>
  11. public static void InsertSummary(AstNode node, IEnumerable<string> lines)
  12. {
  13. if (node?.Parent != null && lines != null)
  14. {
  15. var commentLinesList = lines.ToList();
  16. if (commentLinesList.Count > 0)
  17. {
  18. node.Parent.InsertChildBefore(node, new Comment(" <summary>", CommentType.Documentation), Roles.Comment);
  19. foreach (var comment in commentLinesList)
  20. {
  21. node.Parent.InsertChildBefore(node, new Comment(" " + comment.Trim(' '), CommentType.Documentation), Roles.Comment);
  22. }
  23. node.Parent.InsertChildBefore(node, new Comment(" </summary>", CommentType.Documentation), Roles.Comment);
  24. }
  25. }
  26. }
  27. public static void InsertHeader(SyntaxTree syntaxTree)
  28. {
  29. var lines = new[]
  30. {
  31. "WARNING - AUTOGENERATED - DO NOT EDIT",
  32. "",
  33. "Generated using `sharpie urho`",
  34. "",
  35. syntaxTree.FileName,
  36. "",
  37. "Copyright 2015 Xamarin Inc. All rights reserved.\n",
  38. };
  39. foreach (var line in lines)
  40. syntaxTree.Members.Add(new Comment(" " + line));
  41. }
  42. }
  43. }