예제 #1
0
 public Attributes(ArgumentAttribute input, TlcModule.RangeAttribute range, bool optional = false)
 {
     Contracts.AssertValue(input);
     Contracts.AssertValueOrNull(range);
     Input    = input;
     Range    = range;
     Optional = optional;
 }
예제 #2
0
 public static bool IsValueWithinRange(this TlcModule.RangeAttribute range, object val)
 {
     Contracts.AssertValue(range);
     Contracts.AssertValue(val);
     // Avoid trying to cast double as float. If range
     // was specified using floats, but value being checked
     // is double, change range to be of type double
     if (range.Type == typeof(float) && val is double)
     {
         range.CastToDouble();
     }
     return(Utils.MarshalInvoke(_isValueWithinRangeMethodInfo, range.Type, range, val));
 }
예제 #3
0
        private static bool IsValueWithinRange <T>(TlcModule.RangeAttribute range, object obj)
        {
            T val;

            if (obj is Optional <T> asOptional)
            {
                val = asOptional.Value;
            }
            else
            {
                val = (T)obj;
            }

            return
                ((range.Min == null || ((IComparable)range.Min).CompareTo(val) <= 0) &&
                 (range.Inf == null || ((IComparable)range.Inf).CompareTo(val) < 0) &&
                 (range.Max == null || ((IComparable)range.Max).CompareTo(val) >= 0) &&
                 (range.Sup == null || ((IComparable)range.Sup).CompareTo(val) > 0));
        }