Advertisement
Sharkfists

FancyRange.cs

Dec 7th, 2021
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 KB | None | 0 0
  1. using System;
  2.  
  3. [Serializable]
  4. public class FancyRange<T> where T : IComparable
  5. {
  6.     public T Min;
  7.     public T Max;
  8.  
  9.     public FancyRange()
  10.     {
  11.         Min = default;
  12.         Max = default;
  13.     }
  14.  
  15.     public FancyRange(T min, T max)
  16.     {
  17.         Min = min;
  18.         Max = max;
  19.     }
  20.  
  21.     public virtual bool Contains(T val)
  22.     {
  23.         return val.CompareTo(Min) >= 0 && val.CompareTo(Max) <= 0;
  24.     }
  25.  
  26.     public override string ToString()
  27.     {
  28.         return "(" + Min + ", " + Max + ")";
  29.     }
  30. }
  31.  
  32. [Serializable]
  33. public class FancyIntRange : FancyRange<int>
  34. {
  35.     public FancyIntRange() : base() { }
  36.     public FancyIntRange(int min, int max) : base(min, max) { }
  37. }
  38. [Serializable]
  39. public class FancyFloatRange : FancyRange<float>
  40. {
  41.     public FancyFloatRange() : base() { }
  42.     public FancyFloatRange(float min, float max) : base(min, max) { }
  43. }
  44. [Serializable]
  45. public class FancyDoubleRange : FancyRange<double>
  46. {
  47.     public FancyDoubleRange() : base() { }
  48.     public FancyDoubleRange(double min, double max) : base(min, max) { }
  49. }
  50. [Serializable]
  51. public class FancyLongRange : FancyRange<long>
  52. {
  53.     public FancyLongRange() : base() { }
  54.     public FancyLongRange(long min, long max) : base(min, max) { }
  55. }
  56. [Serializable]
  57. public class FancyShortRange : FancyRange<short>
  58. {
  59.     public FancyShortRange() : base() { }
  60.     public FancyShortRange(short min, short max) : base(min, max) { }
  61. }
  62. [Serializable]
  63. public class FancySByteRange : FancyRange<sbyte>
  64. {
  65.     public FancySByteRange() : base() { }
  66.     public FancySByteRange(sbyte min, sbyte max) : base(min, max) { }
  67. }
  68. [Serializable]
  69. public class FancyByteRange : FancyRange<byte>
  70. {
  71.     public FancyByteRange() : base() { }
  72.     public FancyByteRange(byte min, byte max) : base(min, max) { }
  73. }
  74. [Serializable]
  75. public class FancyUShortRange : FancyRange<ushort>
  76. {
  77.     public FancyUShortRange() : base() { }
  78.     public FancyUShortRange(ushort min, ushort max) : base(min, max) { }
  79. }
  80. [Serializable]
  81. public class FancyUIntRange : FancyRange<uint>
  82. {
  83.     public FancyUIntRange() : base() { }
  84.     public FancyUIntRange(uint min, uint max) : base(min, max) { }
  85. }
  86. [Serializable]
  87. public class FancyULongRange : FancyRange<ulong>
  88. {
  89.     public FancyULongRange() : base() { }
  90.     public FancyULongRange(ulong min, ulong max) : base(min, max) { }
  91. }
  92. [Serializable]
  93. public class FancyDecimalRange : FancyRange<decimal>
  94. {
  95.     public FancyDecimalRange() : base() { }
  96.     public FancyDecimalRange(decimal min, decimal max) : base(min, max) { }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement