示例#1
0
 public object Apply(object a, object b)
 {
     return(a switch {
         // Integral types
         byte bt => Byte?.Invoke(bt, Convert.ToByte(b)),
         sbyte sb => SByte?.Invoke(sb, Convert.ToSByte(b)),
         short sh => Short?.Invoke(sh, Convert.ToInt16(b)),
         ushort ush => UShort?.Invoke(ush, Convert.ToUInt16(b)),
         int i => Int?.Invoke(i, Convert.ToInt32(b)),
         uint ui => UInt?.Invoke(ui, Convert.ToUInt32(b)),
         long l => Long?.Invoke(l, Convert.ToInt64(b)),
         ulong ul => ULong?.Invoke(ul, Convert.ToUInt64(b)),
         float f => Float?.Invoke(f, Convert.ToSingle(b)),
         double d => Double?.Invoke(d, Convert.ToDouble(b)),
         decimal dec => Decimal?.Invoke(dec, Convert.ToDecimal(b)),
         string str => String?.Invoke(str, Convert.ToString(b)),
         DateTime dt => DateTime?.Invoke(dt, TimeUtils.TimeSpanOf(b)),
         TimeSpan ts => TimeSpan?.Invoke(ts, b),
         _ => throw new ArgumentException($"I don't know how to coercively operate on {a.GetType()} and {b.GetType()}!")
     } ?? throw DoesNotApply(a, b));