public static void Deserialize(ListTreeNode <T> src, ref U t) { if (s_d == null) { if (typeof(U).IsEnum) { // enum from string var mi = typeof(Enum).GetMethods(BindingFlags.Static | BindingFlags.Public).First( x => x.Name == "Parse" && x.GetParameters().Length == 3 ); var enumParse = GenericInvokeCallFactory.StaticFunc <Type, string, bool, object>(mi); s_d = x => { var enumValue = enumParse(typeof(U), x.GetString(), true); return(GenericCast <object, U> .Cast(enumValue)); }; } else { s_d = x => GenericCast <string, U> .Cast(x.GetString()); } } t = s_d(src); }
public static void Deserialize(ListTreeNode <T> src, ref U t) { if (s_d == null) { if (typeof(U).IsEnum) { // enum from string var mi = typeof(Enum).GetMethods(BindingFlags.Static | BindingFlags.Public).First( x => x.Name == "Parse" && x.GetParameters().Length == 3 ); var type = Expression.Constant(typeof(U)); var value = Expression.Parameter(typeof(string), "value"); var ic = Expression.Constant(true); var call = Expression.Call(mi, type, value, ic); var lambda = Expression.Lambda(call, value); var func = (Func <string, object>)lambda.Compile(); s_d = x => GenericCast <object, U> .Cast(func(x.GetString())); } else { s_d = x => GenericCast <string, U> .Cast(x.GetString()); } } t = s_d(src); }
public static T Cast(S value) { if (s_cast == null) { s_cast = new CastFunc(GenericCast.CreateCast <S, T>()); } return(s_cast(value)); }
public static Func <T> Const(S value) { if (s_const == null) { s_const = new ConstFuncCreator(GenericCast.CreateConst <S, T>()); } return(s_const(value)); }
public static void Deserialize(ListTreeNode <T> src, ref U dst) { if (s_d == null) { // enum from int s_d = s => GenericCast <int, U> .Cast(s.GetInt32()); } dst = s_d(src); }
public JsonSchemaValidationException Validate <T>(JsonSchemaValidationContext c, T o) { if (Values.Contains(GenericCast <T, int> .Cast(o))) { return(null); } else { return(new JsonSchemaValidationException(c, string.Format("{0} is not valid enum", o))); } }
public T GetValue<T>() { switch (ValueType) { case ValueNodeType.Null: return GenericCast<object, T>.Null(); case ValueNodeType.Boolean: return GenericCast<bool, T>.Cast(GetBoolean()); case ValueNodeType.Integer: return GenericCast<int, T>.Cast(GetInt32()); case ValueNodeType.Number: case ValueNodeType.NaN: case ValueNodeType.Infinity: case ValueNodeType.MinusInfinity: return GenericCast<double, T>.Cast(GetDouble()); case ValueNodeType.String: return GenericCast<string, T>.Cast(GetString()); } throw new NotImplementedException(); }
public static void Serialize(JsonStringEnumValidator validator, IFormatter f, JsonSchemaValidationContext c, T o) { if (s_serializer == null) { var t = typeof(T); if (t.IsEnum) { s_serializer = (vv, ff, cc, oo) => { var value = Enum.GetName(t, oo); if (vv.SerializationType == EnumSerializationType.AsLowerString) { value = value.ToLower(); } else if (vv.SerializationType == EnumSerializationType.AsUpperString) { value = value.ToUpper(); } ff.Value(value); }; } else if (t == typeof(string)) { s_serializer = (vv, ff, cc, oo) => { var value = GenericCast <T, string> .Cast(oo); if (vv.SerializationType == EnumSerializationType.AsLowerString) { value = value.ToLower(); } else if (vv.SerializationType == EnumSerializationType.AsUpperString) { value = value.ToUpper(); } ff.Value(value); }; } else { throw new NotImplementedException(); } } s_serializer(validator, f, c, o); }
public JsonSchemaValidationException Validate <T>(JsonSchemaValidationContext c, T o) { if (o == null) { return(new JsonSchemaValidationException(c, "null")); } var t = o.GetType(); string value = null; if (t.IsEnum) { value = Enum.GetName(t, o); } else { value = GenericCast <T, string> .Cast(o); } if (SerializationType == EnumSerializationType.AsLowerString) { value = value.ToLower(); } else if (SerializationType == EnumSerializationType.AsUpperString) { value = value.ToUpper(); } if (Values.Contains(value)) { return(null); } else { return(new JsonSchemaValidationException(c, string.Format("{0} is not valid enum", o))); } }
/// <summary> /// ArrayとMap以外のタイプの値を得る /// </summary> /// <returns></returns> public T GetValue <T>() { var formatType = Format; switch (formatType) { case MsgPackType.NIL: return(GenericCast <object, T> .Null()); case MsgPackType.TRUE: return(GenericCast <bool, T> .Const(true)()); case MsgPackType.FALSE: return(GenericCast <bool, T> .Const(false)()); case MsgPackType.POSITIVE_FIXNUM: return(GenericCast <int, T> .Const(0)()); case MsgPackType.POSITIVE_FIXNUM_0x01: return(GenericCast <int, T> .Const(1)()); case MsgPackType.POSITIVE_FIXNUM_0x02: return(GenericCast <int, T> .Const(2)()); case MsgPackType.POSITIVE_FIXNUM_0x03: return(GenericCast <int, T> .Const(3)()); case MsgPackType.POSITIVE_FIXNUM_0x04: return(GenericCast <int, T> .Const(4)()); case MsgPackType.POSITIVE_FIXNUM_0x05: return(GenericCast <int, T> .Const(5)()); case MsgPackType.POSITIVE_FIXNUM_0x06: return(GenericCast <int, T> .Const(6)()); case MsgPackType.POSITIVE_FIXNUM_0x07: return(GenericCast <int, T> .Const(7)()); case MsgPackType.POSITIVE_FIXNUM_0x08: return(GenericCast <int, T> .Const(8)()); case MsgPackType.POSITIVE_FIXNUM_0x09: return(GenericCast <int, T> .Const(9)()); case MsgPackType.POSITIVE_FIXNUM_0x0A: return(GenericCast <int, T> .Const(10)()); case MsgPackType.POSITIVE_FIXNUM_0x0B: return(GenericCast <int, T> .Const(11)()); case MsgPackType.POSITIVE_FIXNUM_0x0C: return(GenericCast <int, T> .Const(12)()); case MsgPackType.POSITIVE_FIXNUM_0x0D: return(GenericCast <int, T> .Const(13)()); case MsgPackType.POSITIVE_FIXNUM_0x0E: return(GenericCast <int, T> .Const(14)()); case MsgPackType.POSITIVE_FIXNUM_0x0F: return(GenericCast <int, T> .Const(15)()); case MsgPackType.POSITIVE_FIXNUM_0x10: return(GenericCast <int, T> .Const(16)()); case MsgPackType.POSITIVE_FIXNUM_0x11: return(GenericCast <int, T> .Const(17)()); case MsgPackType.POSITIVE_FIXNUM_0x12: return(GenericCast <int, T> .Const(18)()); case MsgPackType.POSITIVE_FIXNUM_0x13: return(GenericCast <int, T> .Const(19)()); case MsgPackType.POSITIVE_FIXNUM_0x14: return(GenericCast <int, T> .Const(20)()); case MsgPackType.POSITIVE_FIXNUM_0x15: return(GenericCast <int, T> .Const(21)()); case MsgPackType.POSITIVE_FIXNUM_0x16: return(GenericCast <int, T> .Const(22)()); case MsgPackType.POSITIVE_FIXNUM_0x17: return(GenericCast <int, T> .Const(23)()); case MsgPackType.POSITIVE_FIXNUM_0x18: return(GenericCast <int, T> .Const(24)()); case MsgPackType.POSITIVE_FIXNUM_0x19: return(GenericCast <int, T> .Const(25)()); case MsgPackType.POSITIVE_FIXNUM_0x1A: return(GenericCast <int, T> .Const(26)()); case MsgPackType.POSITIVE_FIXNUM_0x1B: return(GenericCast <int, T> .Const(27)()); case MsgPackType.POSITIVE_FIXNUM_0x1C: return(GenericCast <int, T> .Const(28)()); case MsgPackType.POSITIVE_FIXNUM_0x1D: return(GenericCast <int, T> .Const(29)()); case MsgPackType.POSITIVE_FIXNUM_0x1E: return(GenericCast <int, T> .Const(30)()); case MsgPackType.POSITIVE_FIXNUM_0x1F: return(GenericCast <int, T> .Const(31)()); case MsgPackType.POSITIVE_FIXNUM_0x20: return(GenericCast <int, T> .Const(32)()); case MsgPackType.POSITIVE_FIXNUM_0x21: return(GenericCast <int, T> .Const(33)()); case MsgPackType.POSITIVE_FIXNUM_0x22: return(GenericCast <int, T> .Const(34)()); case MsgPackType.POSITIVE_FIXNUM_0x23: return(GenericCast <int, T> .Const(35)()); case MsgPackType.POSITIVE_FIXNUM_0x24: return(GenericCast <int, T> .Const(36)()); case MsgPackType.POSITIVE_FIXNUM_0x25: return(GenericCast <int, T> .Const(37)()); case MsgPackType.POSITIVE_FIXNUM_0x26: return(GenericCast <int, T> .Const(38)()); case MsgPackType.POSITIVE_FIXNUM_0x27: return(GenericCast <int, T> .Const(39)()); case MsgPackType.POSITIVE_FIXNUM_0x28: return(GenericCast <int, T> .Const(40)()); case MsgPackType.POSITIVE_FIXNUM_0x29: return(GenericCast <int, T> .Const(41)()); case MsgPackType.POSITIVE_FIXNUM_0x2A: return(GenericCast <int, T> .Const(42)()); case MsgPackType.POSITIVE_FIXNUM_0x2B: return(GenericCast <int, T> .Const(43)()); case MsgPackType.POSITIVE_FIXNUM_0x2C: return(GenericCast <int, T> .Const(44)()); case MsgPackType.POSITIVE_FIXNUM_0x2D: return(GenericCast <int, T> .Const(45)()); case MsgPackType.POSITIVE_FIXNUM_0x2E: return(GenericCast <int, T> .Const(46)()); case MsgPackType.POSITIVE_FIXNUM_0x2F: return(GenericCast <int, T> .Const(47)()); case MsgPackType.POSITIVE_FIXNUM_0x30: return(GenericCast <int, T> .Const(48)()); case MsgPackType.POSITIVE_FIXNUM_0x31: return(GenericCast <int, T> .Const(49)()); case MsgPackType.POSITIVE_FIXNUM_0x32: return(GenericCast <int, T> .Const(50)()); case MsgPackType.POSITIVE_FIXNUM_0x33: return(GenericCast <int, T> .Const(51)()); case MsgPackType.POSITIVE_FIXNUM_0x34: return(GenericCast <int, T> .Const(52)()); case MsgPackType.POSITIVE_FIXNUM_0x35: return(GenericCast <int, T> .Const(53)()); case MsgPackType.POSITIVE_FIXNUM_0x36: return(GenericCast <int, T> .Const(54)()); case MsgPackType.POSITIVE_FIXNUM_0x37: return(GenericCast <int, T> .Const(55)()); case MsgPackType.POSITIVE_FIXNUM_0x38: return(GenericCast <int, T> .Const(56)()); case MsgPackType.POSITIVE_FIXNUM_0x39: return(GenericCast <int, T> .Const(57)()); case MsgPackType.POSITIVE_FIXNUM_0x3A: return(GenericCast <int, T> .Const(58)()); case MsgPackType.POSITIVE_FIXNUM_0x3B: return(GenericCast <int, T> .Const(59)()); case MsgPackType.POSITIVE_FIXNUM_0x3C: return(GenericCast <int, T> .Const(60)()); case MsgPackType.POSITIVE_FIXNUM_0x3D: return(GenericCast <int, T> .Const(61)()); case MsgPackType.POSITIVE_FIXNUM_0x3E: return(GenericCast <int, T> .Const(62)()); case MsgPackType.POSITIVE_FIXNUM_0x3F: return(GenericCast <int, T> .Const(63)()); case MsgPackType.POSITIVE_FIXNUM_0x40: return(GenericCast <int, T> .Const(64)()); case MsgPackType.POSITIVE_FIXNUM_0x41: return(GenericCast <int, T> .Const(65)()); case MsgPackType.POSITIVE_FIXNUM_0x42: return(GenericCast <int, T> .Const(66)()); case MsgPackType.POSITIVE_FIXNUM_0x43: return(GenericCast <int, T> .Const(67)()); case MsgPackType.POSITIVE_FIXNUM_0x44: return(GenericCast <int, T> .Const(68)()); case MsgPackType.POSITIVE_FIXNUM_0x45: return(GenericCast <int, T> .Const(69)()); case MsgPackType.POSITIVE_FIXNUM_0x46: return(GenericCast <int, T> .Const(70)()); case MsgPackType.POSITIVE_FIXNUM_0x47: return(GenericCast <int, T> .Const(71)()); case MsgPackType.POSITIVE_FIXNUM_0x48: return(GenericCast <int, T> .Const(72)()); case MsgPackType.POSITIVE_FIXNUM_0x49: return(GenericCast <int, T> .Const(73)()); case MsgPackType.POSITIVE_FIXNUM_0x4A: return(GenericCast <int, T> .Const(74)()); case MsgPackType.POSITIVE_FIXNUM_0x4B: return(GenericCast <int, T> .Const(75)()); case MsgPackType.POSITIVE_FIXNUM_0x4C: return(GenericCast <int, T> .Const(76)()); case MsgPackType.POSITIVE_FIXNUM_0x4D: return(GenericCast <int, T> .Const(77)()); case MsgPackType.POSITIVE_FIXNUM_0x4E: return(GenericCast <int, T> .Const(78)()); case MsgPackType.POSITIVE_FIXNUM_0x4F: return(GenericCast <int, T> .Const(79)()); case MsgPackType.POSITIVE_FIXNUM_0x50: return(GenericCast <int, T> .Const(80)()); case MsgPackType.POSITIVE_FIXNUM_0x51: return(GenericCast <int, T> .Const(81)()); case MsgPackType.POSITIVE_FIXNUM_0x52: return(GenericCast <int, T> .Const(82)()); case MsgPackType.POSITIVE_FIXNUM_0x53: return(GenericCast <int, T> .Const(83)()); case MsgPackType.POSITIVE_FIXNUM_0x54: return(GenericCast <int, T> .Const(84)()); case MsgPackType.POSITIVE_FIXNUM_0x55: return(GenericCast <int, T> .Const(85)()); case MsgPackType.POSITIVE_FIXNUM_0x56: return(GenericCast <int, T> .Const(86)()); case MsgPackType.POSITIVE_FIXNUM_0x57: return(GenericCast <int, T> .Const(87)()); case MsgPackType.POSITIVE_FIXNUM_0x58: return(GenericCast <int, T> .Const(88)()); case MsgPackType.POSITIVE_FIXNUM_0x59: return(GenericCast <int, T> .Const(89)()); case MsgPackType.POSITIVE_FIXNUM_0x5A: return(GenericCast <int, T> .Const(90)()); case MsgPackType.POSITIVE_FIXNUM_0x5B: return(GenericCast <int, T> .Const(91)()); case MsgPackType.POSITIVE_FIXNUM_0x5C: return(GenericCast <int, T> .Const(92)()); case MsgPackType.POSITIVE_FIXNUM_0x5D: return(GenericCast <int, T> .Const(93)()); case MsgPackType.POSITIVE_FIXNUM_0x5E: return(GenericCast <int, T> .Const(94)()); case MsgPackType.POSITIVE_FIXNUM_0x5F: return(GenericCast <int, T> .Const(95)()); case MsgPackType.POSITIVE_FIXNUM_0x60: return(GenericCast <int, T> .Const(96)()); case MsgPackType.POSITIVE_FIXNUM_0x61: return(GenericCast <int, T> .Const(97)()); case MsgPackType.POSITIVE_FIXNUM_0x62: return(GenericCast <int, T> .Const(98)()); case MsgPackType.POSITIVE_FIXNUM_0x63: return(GenericCast <int, T> .Const(99)()); case MsgPackType.POSITIVE_FIXNUM_0x64: return(GenericCast <int, T> .Const(100)()); case MsgPackType.POSITIVE_FIXNUM_0x65: return(GenericCast <int, T> .Const(101)()); case MsgPackType.POSITIVE_FIXNUM_0x66: return(GenericCast <int, T> .Const(102)()); case MsgPackType.POSITIVE_FIXNUM_0x67: return(GenericCast <int, T> .Const(103)()); case MsgPackType.POSITIVE_FIXNUM_0x68: return(GenericCast <int, T> .Const(104)()); case MsgPackType.POSITIVE_FIXNUM_0x69: return(GenericCast <int, T> .Const(105)()); case MsgPackType.POSITIVE_FIXNUM_0x6A: return(GenericCast <int, T> .Const(106)()); case MsgPackType.POSITIVE_FIXNUM_0x6B: return(GenericCast <int, T> .Const(107)()); case MsgPackType.POSITIVE_FIXNUM_0x6C: return(GenericCast <int, T> .Const(108)()); case MsgPackType.POSITIVE_FIXNUM_0x6D: return(GenericCast <int, T> .Const(109)()); case MsgPackType.POSITIVE_FIXNUM_0x6E: return(GenericCast <int, T> .Const(110)()); case MsgPackType.POSITIVE_FIXNUM_0x6F: return(GenericCast <int, T> .Const(111)()); case MsgPackType.POSITIVE_FIXNUM_0x70: return(GenericCast <int, T> .Const(112)()); case MsgPackType.POSITIVE_FIXNUM_0x71: return(GenericCast <int, T> .Const(113)()); case MsgPackType.POSITIVE_FIXNUM_0x72: return(GenericCast <int, T> .Const(114)()); case MsgPackType.POSITIVE_FIXNUM_0x73: return(GenericCast <int, T> .Const(115)()); case MsgPackType.POSITIVE_FIXNUM_0x74: return(GenericCast <int, T> .Const(116)()); case MsgPackType.POSITIVE_FIXNUM_0x75: return(GenericCast <int, T> .Const(117)()); case MsgPackType.POSITIVE_FIXNUM_0x76: return(GenericCast <int, T> .Const(118)()); case MsgPackType.POSITIVE_FIXNUM_0x77: return(GenericCast <int, T> .Const(119)()); case MsgPackType.POSITIVE_FIXNUM_0x78: return(GenericCast <int, T> .Const(120)()); case MsgPackType.POSITIVE_FIXNUM_0x79: return(GenericCast <int, T> .Const(121)()); case MsgPackType.POSITIVE_FIXNUM_0x7A: return(GenericCast <int, T> .Const(122)()); case MsgPackType.POSITIVE_FIXNUM_0x7B: return(GenericCast <int, T> .Const(123)()); case MsgPackType.POSITIVE_FIXNUM_0x7C: return(GenericCast <int, T> .Const(124)()); case MsgPackType.POSITIVE_FIXNUM_0x7D: return(GenericCast <int, T> .Const(125)()); case MsgPackType.POSITIVE_FIXNUM_0x7E: return(GenericCast <int, T> .Const(126)()); case MsgPackType.POSITIVE_FIXNUM_0x7F: return(GenericCast <int, T> .Const(127)()); case MsgPackType.NEGATIVE_FIXNUM: return(GenericCast <int, T> .Const(-32)()); case MsgPackType.NEGATIVE_FIXNUM_0x01: return(GenericCast <int, T> .Const(-1)()); case MsgPackType.NEGATIVE_FIXNUM_0x02: return(GenericCast <int, T> .Const(-2)()); case MsgPackType.NEGATIVE_FIXNUM_0x03: return(GenericCast <int, T> .Const(-3)()); case MsgPackType.NEGATIVE_FIXNUM_0x04: return(GenericCast <int, T> .Const(-4)()); case MsgPackType.NEGATIVE_FIXNUM_0x05: return(GenericCast <int, T> .Const(-5)()); case MsgPackType.NEGATIVE_FIXNUM_0x06: return(GenericCast <int, T> .Const(-6)()); case MsgPackType.NEGATIVE_FIXNUM_0x07: return(GenericCast <int, T> .Const(-7)()); case MsgPackType.NEGATIVE_FIXNUM_0x08: return(GenericCast <int, T> .Const(-8)()); case MsgPackType.NEGATIVE_FIXNUM_0x09: return(GenericCast <int, T> .Const(-9)()); case MsgPackType.NEGATIVE_FIXNUM_0x0A: return(GenericCast <int, T> .Const(-10)()); case MsgPackType.NEGATIVE_FIXNUM_0x0B: return(GenericCast <int, T> .Const(-11)()); case MsgPackType.NEGATIVE_FIXNUM_0x0C: return(GenericCast <int, T> .Const(-12)()); case MsgPackType.NEGATIVE_FIXNUM_0x0D: return(GenericCast <int, T> .Const(-13)()); case MsgPackType.NEGATIVE_FIXNUM_0x0E: return(GenericCast <int, T> .Const(-14)()); case MsgPackType.NEGATIVE_FIXNUM_0x0F: return(GenericCast <int, T> .Const(-15)()); case MsgPackType.NEGATIVE_FIXNUM_0x10: return(GenericCast <int, T> .Const(-16)()); case MsgPackType.NEGATIVE_FIXNUM_0x11: return(GenericCast <int, T> .Const(-17)()); case MsgPackType.NEGATIVE_FIXNUM_0x12: return(GenericCast <int, T> .Const(-18)()); case MsgPackType.NEGATIVE_FIXNUM_0x13: return(GenericCast <int, T> .Const(-19)()); case MsgPackType.NEGATIVE_FIXNUM_0x14: return(GenericCast <int, T> .Const(-20)()); case MsgPackType.NEGATIVE_FIXNUM_0x15: return(GenericCast <int, T> .Const(-21)()); case MsgPackType.NEGATIVE_FIXNUM_0x16: return(GenericCast <int, T> .Const(-22)()); case MsgPackType.NEGATIVE_FIXNUM_0x17: return(GenericCast <int, T> .Const(-23)()); case MsgPackType.NEGATIVE_FIXNUM_0x18: return(GenericCast <int, T> .Const(-24)()); case MsgPackType.NEGATIVE_FIXNUM_0x19: return(GenericCast <int, T> .Const(-25)()); case MsgPackType.NEGATIVE_FIXNUM_0x1A: return(GenericCast <int, T> .Const(-26)()); case MsgPackType.NEGATIVE_FIXNUM_0x1B: return(GenericCast <int, T> .Const(-27)()); case MsgPackType.NEGATIVE_FIXNUM_0x1C: return(GenericCast <int, T> .Const(-28)()); case MsgPackType.NEGATIVE_FIXNUM_0x1D: return(GenericCast <int, T> .Const(-29)()); case MsgPackType.NEGATIVE_FIXNUM_0x1E: return(GenericCast <int, T> .Const(-30)()); case MsgPackType.NEGATIVE_FIXNUM_0x1F: return(GenericCast <int, T> .Const(-31)()); case MsgPackType.INT8: return(GenericCast <SByte, T> .Cast((SByte)GetBody().Get(0))); case MsgPackType.INT16: return(GenericCast <short, T> .Cast(EndianConverter.NetworkByteWordToSignedNativeByteOrder(GetBody()))); case MsgPackType.INT32: return(GenericCast <int, T> .Cast(EndianConverter.NetworkByteDWordToSignedNativeByteOrder(GetBody()))); case MsgPackType.INT64: return(GenericCast <long, T> .Cast(EndianConverter.NetworkByteQWordToSignedNativeByteOrder(GetBody()))); case MsgPackType.UINT8: return(GenericCast <Byte, T> .Cast(GetBody().Get(0))); case MsgPackType.UINT16: return(GenericCast <ushort, T> .Cast(EndianConverter.NetworkByteWordToUnsignedNativeByteOrder(GetBody()))); case MsgPackType.UINT32: return(GenericCast <uint, T> .Cast(EndianConverter.NetworkByteDWordToUnsignedNativeByteOrder(GetBody()))); case MsgPackType.UINT64: return(GenericCast <ulong, T> .Cast(EndianConverter.NetworkByteQWordToUnsignedNativeByteOrder(GetBody()))); case MsgPackType.FLOAT: return(GenericCast <float, T> .Cast(EndianConverter.NetworkByteDWordToFloatNativeByteOrder(GetBody()))); case MsgPackType.DOUBLE: return(GenericCast <double, T> .Cast(EndianConverter.NetworkByteQWordToFloatNativeByteOrder(GetBody()))); case MsgPackType.FIX_STR: return(GenericCast <string, T> .Const("")()); case MsgPackType.FIX_STR_0x01: case MsgPackType.FIX_STR_0x02: case MsgPackType.FIX_STR_0x03: case MsgPackType.FIX_STR_0x04: case MsgPackType.FIX_STR_0x05: case MsgPackType.FIX_STR_0x06: case MsgPackType.FIX_STR_0x07: case MsgPackType.FIX_STR_0x08: case MsgPackType.FIX_STR_0x09: case MsgPackType.FIX_STR_0x0A: case MsgPackType.FIX_STR_0x0B: case MsgPackType.FIX_STR_0x0C: case MsgPackType.FIX_STR_0x0D: case MsgPackType.FIX_STR_0x0E: case MsgPackType.FIX_STR_0x0F: case MsgPackType.FIX_STR_0x10: case MsgPackType.FIX_STR_0x11: case MsgPackType.FIX_STR_0x12: case MsgPackType.FIX_STR_0x13: case MsgPackType.FIX_STR_0x14: case MsgPackType.FIX_STR_0x15: case MsgPackType.FIX_STR_0x16: case MsgPackType.FIX_STR_0x17: case MsgPackType.FIX_STR_0x18: case MsgPackType.FIX_STR_0x19: case MsgPackType.FIX_STR_0x1A: case MsgPackType.FIX_STR_0x1B: case MsgPackType.FIX_STR_0x1C: case MsgPackType.FIX_STR_0x1D: case MsgPackType.FIX_STR_0x1E: case MsgPackType.FIX_STR_0x1F: case MsgPackType.STR8: case MsgPackType.STR16: case MsgPackType.STR32: { var body = GetBody(); var str = Encoding.UTF8.GetString(body.Array, body.Offset, body.Count); return(GenericCast <string, T> .Cast(str)); } case MsgPackType.BIN8: case MsgPackType.BIN16: case MsgPackType.BIN32: { var body = GetBody(); return(GenericCast <ArraySegment <Byte>, T> .Cast(body)); } case MsgPackType.FIX_EXT_4: { if (GetExtType() == -1) { var unixtime = EndianConverter.NetworkByteDWordToUnsignedNativeByteOrder(GetBody()); var dt = new DateTimeOffset(unixtime * DateTimeOffsetExtensions.TicksPerSecond + DateTimeOffsetExtensions.EpochTime.Ticks, TimeSpan.Zero); return(GenericCast <DateTimeOffset, T> .Cast(dt)); } break; } } throw new ArgumentException("GetValue to array or map: " + formatType); }
public void Deserialize <T, U>(ListTreeNode <T> src, ref U dst) where T : IListTreeItem, IValue <T> { dst = GenericCast <string, U> .Cast(src.GetString()); }
public void Serialize <T>(IFormatter f, JsonSchemaValidationContext c, T o) { f.Value(GenericCast <T, string> .Cast(o)); }
public void Deserialize <T, U>(ListTreeNode <T> src, ref U dst) where T : IListTreeItem, IValue <T> { dst = GenericCast <bool, U> .Cast(src.GetBoolean()); }
public JsonSchemaValidationException Validate <T>(JsonSchemaValidationContext c, T o) { try { var value = GenericCast <T, int> .Cast(o); if (Minimum.HasValue) { if (ExclusiveMinimum) { if (value > Minimum.Value) { // ok } else { return(new JsonSchemaValidationException(c, string.Format("minimum: ! {0}>{1}", value, Minimum.Value))); } } else { if (value >= Minimum.Value) { // ok } else { return(new JsonSchemaValidationException(c, string.Format("minimum: ! {0}>={1}", value, Minimum.Value))); } } } if (Maximum.HasValue) { if (ExclusiveMaximum) { if (value < Maximum.Value) { // ok } else { return(new JsonSchemaValidationException(c, string.Format("maximum: ! {0}<{1}", value, Maximum.Value))); } } else { if (value <= Maximum.Value) { // ok } else { return(new JsonSchemaValidationException(c, string.Format("maximum: ! {0}<={1}", value, Maximum.Value))); } } } if (MultipleOf.HasValue && value % MultipleOf.Value != 0) { return(new JsonSchemaValidationException(c, string.Format("multipleOf: {0}%{1}", value, MultipleOf.Value))); } return(null); } catch (Exception ex) { return(new JsonSchemaValidationException(c, ex)); } }