AbstractArgument.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Text;
  3. using Quadarax.Foundation.Core.QConsole.Value;
  4. namespace Quadarax.Foundation.Core.QConsole.Argument
  5. {
  6. public abstract class AbstractArgument
  7. {
  8. #region *** Properties ***
  9. /// <summary>
  10. /// Defines access code to argument
  11. /// <example>
  12. /// c, a, file, path, ...
  13. /// </example>
  14. /// </summary>
  15. public string Code { get; }
  16. /// <summary>
  17. /// Defines name of value in short displaying form
  18. /// <example>
  19. /// file_name, name_of_database, number, ...
  20. /// </example>
  21. /// </summary>
  22. public string Hint { get; }
  23. /// <summary>
  24. /// Full description for argument
  25. /// </summary>
  26. public string Description { get; }
  27. /// <summary>
  28. /// Defines if argument is mandatory. If True, then if argument is not specified, then error occures.
  29. /// </summary>
  30. public bool IsMandatory { get; }
  31. /// <summary>
  32. /// Current value of argument
  33. /// </summary>
  34. public AbstractValue Value { get; }
  35. /// <summary>
  36. /// Default value of argument, uses if argument is not specified.
  37. /// </summary>
  38. public AbstractValue DefaultValue { get; }
  39. #endregion
  40. #region *** Constructors ***
  41. #endregion
  42. #region *** Public operations ***
  43. public AbstractArgument(string code, string description, string hint, TypeValuesEnum valueType, string defaultValue, bool isMandatory)
  44. {
  45. if (string.IsNullOrEmpty(code))
  46. throw new ArgumentNullException();
  47. Code = code;
  48. Description = description;
  49. Hint = hint;
  50. IsMandatory = isMandatory;
  51. Value = AbstractValue.Create(valueType);
  52. DefaultValue = AbstractValue.Create(valueType);
  53. DefaultValue.Set(defaultValue);
  54. }
  55. #endregion
  56. public void SetValueAsDefault()
  57. {
  58. if (DefaultValue.HasValue)
  59. Value.Set(DefaultValue.Get());
  60. }
  61. public override string ToString()
  62. {
  63. var sb = new StringBuilder();
  64. sb.Append("[").Append(Code).Append("] ").Append(Hint);
  65. return sb.ToString();
  66. }
  67. }
  68. }