Guest User

Untitled

a guest
Jun 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConfigurationFileParser
  9. {
  10.  
  11. /// <summary>
  12. /// Base class describing rules of the specified type of element.
  13. /// </summary>
  14. public abstract class AbstractElement<T> where T : AbstractElement<T>, new()
  15. {
  16. /// Type of the element on which the element is applied.
  17. /// </summary>
  18. protected ElementType ElementTypeValue;
  19. /// <summary>
  20. /// Element comment.
  21. /// </summary>
  22. protected string comment;
  23. /// <summary>
  24. /// Definition whether the element is array.
  25. /// </summary>
  26. private bool isArrayValue;
  27. /// <summary>
  28. /// Current content of line.
  29. /// </summary>
  30. private Line content;
  31.  
  32. /// <summary>
  33. /// Desfault constructor of the AbstractElementRule class.
  34. /// </summary>
  35. protected AbstractElement()
  36. {
  37. }
  38.  
  39. /// <summary>
  40. /// Gets the type of the element on which the rule is applied.
  41. /// </summary>
  42. public ElementType ElementType
  43. {
  44. get
  45. {
  46. return ElementTypeValue;
  47. }
  48. }
  49.  
  50. /// <summary>
  51. /// Gets the definition whether the element is array.
  52. /// </summary>
  53. public bool IsArray()
  54. {
  55. return isArrayValue;
  56. }
  57.  
  58. /// <summary>
  59. /// Sets the comment related to this line.
  60. /// </summary>
  61. public bool SetComment(string tmp)
  62. {
  63. comment = tmp;
  64. return true;
  65. }
  66.  
  67. /// <summary>
  68. /// Parses Element from the lines of the rule description.
  69. /// </summary>
  70. /// <returns>The Element description object for the specified type if description is valid otherwise null.</returns>
  71. /// <param name="logFile">log file where error messages are printed</param>
  72. /// <param name="element">Line of the Element description</param>
  73. /// <exception cref="NotImpelementedException">Method in base class is not implemented.</exception>
  74. public static T ParseElement(StreamWriter logFile, Line element)
  75. {
  76. throw new NotImplementedException("Method not implemented please use the overriden method of the descendants.");
  77. }
  78. }
  79. }
  80.  
  81. namespace ConfigurationFileParser
  82. {
  83. public class ArrayOfElements : AbstractElement<ArrayOfElements>
  84. {
  85. /// <summary>
  86. /// Type of the array.
  87. /// </summary>
  88. protected ElementType ElementTypeValue;
  89.  
  90. /// <summary>
  91. /// Contains array of Elements.
  92. /// </summary>
  93. protected AbstractElement[] elements;
  94.  
  95.  
  96. }
  97. }
  98.  
  99. // Создаю массив наследников.
  100. var arr = new AbstactElement<object>[5];
  101. arr[0] = new A2<object>();
  102. arr[1] = new A3<object>();
  103. arr[2] = new A2<object>();
  104. arr[0].data = '5';
  105. arr[1].data = "dummystring";
  106. arr[2].data = new List<int>();
  107. var a = (List<int>)arr[2].data;
  108. a.Add(2341);
  109. Console.WriteLine((arr[2].data as List<int>)[0]);
  110.  
  111. public abstract class AbstactElement<T>
  112. {
  113. public object data;
  114. }
  115.  
  116. public class A2<T> : AbstactElement<T>
  117. {
  118.  
  119. }
  120.  
  121. public class A3<T> : AbstactElement<T>
  122. {
  123.  
  124. }
Add Comment
Please, Sign In to add comment