GroupUtils.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace FastReport.Export.Dxf.Groups
  5. {
  6. public static class GroupUtils
  7. {
  8. #region Public Methods
  9. public static void AppendGroup<T>(List<GroupBase> groups, int code, T value)
  10. {
  11. groups.Add(CreateGroup(code, value));
  12. }
  13. public static GroupBase CreateGroup<T>(int code, T value)
  14. {
  15. GroupBase group;
  16. if (typeof(T) == typeof(double))
  17. group = new GroupDouble(code, Convert.ToDouble(value));
  18. else if (typeof(T) == typeof(string))
  19. group = new GroupString(code, Convert.ToString(value));
  20. else
  21. group = new Group<T>(code, value);
  22. return group;
  23. }
  24. public static GroupBase CreateGroupComment(int code, string value)
  25. {
  26. return CreateGroup(code, value);
  27. }
  28. public static GroupBase CreateGroupDouble(int code, double value)
  29. {
  30. return CreateGroup(code, value);
  31. }
  32. public static GroupBase CreateGroupString(int code, string value)
  33. {
  34. return CreateGroup(code, value);
  35. }
  36. /// <summary>
  37. /// Sets Name group
  38. /// </summary>
  39. /// <param name="value">Name (attribute tag, block name, and so on)</param>
  40. public static GroupBase CreateName(string value)
  41. {
  42. return CreateGroupString(2, value);
  43. }
  44. /// <summary>
  45. /// Sets Name group
  46. /// </summary>
  47. /// <param name="value">Name (attribute tag, block name, ENDSEC, and so on)</param>
  48. public static GroupBase CreateTypeName(string value)
  49. {
  50. return CreateGroupString(0, value);
  51. }
  52. public static void GroupsAppendTo(List<GroupBase> groups, StringBuilder sectionString)
  53. {
  54. foreach (GroupBase group in groups)
  55. {
  56. group.AppendTo(sectionString);
  57. if (group != groups[groups.Count - 1])
  58. sectionString.Append("\n");
  59. }
  60. }
  61. #endregion Public Methods
  62. }
  63. }