Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Threading.Tasks;
- namespace ConfigurationFileParser
- {
- /// <summary>
- /// Base class describing rules of the specified type of element.
- /// </summary>
- public abstract class AbstractElement<T> where T : AbstractElement<T>, new()
- {
- /// Type of the element on which the element is applied.
- /// </summary>
- protected ElementType ElementTypeValue;
- /// <summary>
- /// Element comment.
- /// </summary>
- protected string comment;
- /// <summary>
- /// Definition whether the element is array.
- /// </summary>
- private bool isArrayValue;
- /// <summary>
- /// Current content of line.
- /// </summary>
- private Line content;
- /// <summary>
- /// Desfault constructor of the AbstractElementRule class.
- /// </summary>
- protected AbstractElement()
- {
- }
- /// <summary>
- /// Gets the type of the element on which the rule is applied.
- /// </summary>
- public ElementType ElementType
- {
- get
- {
- return ElementTypeValue;
- }
- }
- /// <summary>
- /// Gets the definition whether the element is array.
- /// </summary>
- public bool IsArray()
- {
- return isArrayValue;
- }
- /// <summary>
- /// Sets the comment related to this line.
- /// </summary>
- public bool SetComment(string tmp)
- {
- comment = tmp;
- return true;
- }
- /// <summary>
- /// Parses Element from the lines of the rule description.
- /// </summary>
- /// <returns>The Element description object for the specified type if description is valid otherwise null.</returns>
- /// <param name="logFile">log file where error messages are printed</param>
- /// <param name="element">Line of the Element description</param>
- /// <exception cref="NotImpelementedException">Method in base class is not implemented.</exception>
- public static T ParseElement(StreamWriter logFile, Line element)
- {
- throw new NotImplementedException("Method not implemented please use the overriden method of the descendants.");
- }
- }
- }
- namespace ConfigurationFileParser
- {
- public class ArrayOfElements : AbstractElement<ArrayOfElements>
- {
- /// <summary>
- /// Type of the array.
- /// </summary>
- protected ElementType ElementTypeValue;
- /// <summary>
- /// Contains array of Elements.
- /// </summary>
- protected AbstractElement[] elements;
- }
- }
- // Создаю массив наследников.
- var arr = new AbstactElement<object>[5];
- arr[0] = new A2<object>();
- arr[1] = new A3<object>();
- arr[2] = new A2<object>();
- arr[0].data = '5';
- arr[1].data = "dummystring";
- arr[2].data = new List<int>();
- var a = (List<int>)arr[2].data;
- a.Add(2341);
- Console.WriteLine((arr[2].data as List<int>)[0]);
- public abstract class AbstactElement<T>
- {
- public object data;
- }
- public class A2<T> : AbstactElement<T>
- {
- }
- public class A3<T> : AbstactElement<T>
- {
- }
Add Comment
Please, Sign In to add comment