You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace IPA.Config.Data
  7. {
  8. /// <summary>
  9. /// A <see cref="Value"/> representing a piece of text. The only reason this is not named
  10. /// String is so that it doesn't conflict with <see cref="string"/>.
  11. /// </summary>
  12. public sealed class Text : Value
  13. {
  14. /// <summary>
  15. /// The actual value of this <see cref="Text"/> object.
  16. /// </summary>
  17. public string Value { get; set; }
  18. /// <summary>
  19. /// Converts this <see cref="Data.Value"/> into a human-readable format.
  20. /// </summary>
  21. /// <returns>a quoted, unescaped string form of <see cref="Value"/></returns>
  22. public override string ToString() => $"\"{Value}\"";
  23. }
  24. /// <summary>
  25. /// A <see cref="Value"/> representing an integer. This may hold a <see cref="long"/>'s
  26. /// worth of data.
  27. /// </summary>
  28. public sealed class Integer : Value
  29. {
  30. /// <summary>
  31. /// The actual value of the <see cref="Integer"/> object.
  32. /// </summary>
  33. public long Value { get; set; }
  34. /// <summary>
  35. /// Coerces this <see cref="Integer"/> into a <see cref="FloatingPoint"/>.
  36. /// </summary>
  37. /// <returns>a <see cref="FloatingPoint"/> representing the closest approximation of <see cref="Value"/></returns>
  38. public FloatingPoint AsFloat() => Float(Value);
  39. /// <summary>
  40. /// Converts this <see cref="Data.Value"/> into a human-readable format.
  41. /// </summary>
  42. /// <returns>the result of <c>Value.ToString()</c></returns>
  43. public override string ToString() => Value.ToString();
  44. }
  45. /// <summary>
  46. /// A <see cref="Value"/> representing a floating point value. This may hold a
  47. /// <see cref="decimal"/>'s worth of data.
  48. /// </summary>
  49. public sealed class FloatingPoint : Value
  50. {
  51. /// <summary>
  52. /// The actual value fo this <see cref="FloatingPoint"/> object.
  53. /// </summary>
  54. public decimal Value { get; set; }
  55. /// <summary>
  56. /// Coerces this <see cref="FloatingPoint"/> into an <see cref="Integer"/>.
  57. /// </summary>
  58. /// <returns>a <see cref="Integer"/> representing the closest approximation of <see cref="Value"/></returns>
  59. public Integer AsInteger() => Integer((long)Value);
  60. /// <summary>
  61. /// Converts this <see cref="Data.Value"/> into a human-readable format.
  62. /// </summary>
  63. /// <returns>the result of <c>Value.ToString()</c></returns>
  64. public override string ToString() => Value.ToString();
  65. }
  66. /// <summary>
  67. /// A <see cref="Value"/> representing a boolean value.
  68. /// </summary>
  69. public sealed class Boolean : Value
  70. {
  71. /// <summary>
  72. /// The actual value fo this <see cref="Boolean"/> object.
  73. /// </summary>
  74. public bool Value { get; set; }
  75. /// <summary>
  76. /// Converts this <see cref="Data.Value"/> into a human-readable format.
  77. /// </summary>
  78. /// <returns>the result of <c>Value.ToString().ToLower()</c></returns>
  79. public override string ToString() => Value.ToString().ToLower();
  80. }
  81. }