public CompiledMethods(Type type) { var ti = type.GetTypeInfo(); var param0 = Expression.Parameter(typeof(MessagePackSerializer), "serializer"); { // public static byte[] Serialize<T>(T obj) var serialize = GetMethod(type, new Type[] { null }); var param1 = Expression.Parameter(typeof(object), "obj"); var body = Expression.Call( param0, serialize, ti.IsValueType ? Expression.Unbox(param1, type) : Expression.Convert(param1, type)); var lambda = Expression.Lambda <Func <MessagePackSerializer, object, byte[]> >(body, param0, param1).Compile(); this.serialize1 = lambda; } { // public static byte[] Serialize<T>(T obj, IFormatterResolver resolver) var serialize = GetMethod(type, new Type[] { null, typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(object), "obj"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "formatterResolver"); var body = Expression.Call( param0, serialize, ti.IsValueType ? Expression.Unbox(param1, type) : Expression.Convert(param1, type), param2); var lambda = Expression.Lambda <Func <MessagePackSerializer, object, IFormatterResolver, byte[]> >(body, param0, param1, param2).Compile(); this.serialize2 = lambda; } { // public static void Serialize<T>(Stream stream, T obj) var serialize = GetMethod(type, new Type[] { typeof(Stream), null }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(object), "obj"); var body = Expression.Call( param0, serialize, param1, ti.IsValueType ? Expression.Unbox(param2, type) : Expression.Convert(param2, type)); var lambda = Expression.Lambda <Action <MessagePackSerializer, Stream, object> >(body, param0, param1, param2).Compile(); this.serialize3 = lambda; } { // public static void Serialize<T>(Stream stream, T obj, IFormatterResolver resolver) var serialize = GetMethod(type, new Type[] { typeof(Stream), null, typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(object), "obj"); var param3 = Expression.Parameter(typeof(IFormatterResolver), "formatterResolver"); var body = Expression.Call( param0, serialize, param1, ti.IsValueType ? Expression.Unbox(param2, type) : Expression.Convert(param2, type), param3); var lambda = Expression.Lambda <Action <MessagePackSerializer, Stream, object, IFormatterResolver> >(body, param0, param1, param2, param3).Compile(); this.serialize4 = lambda; } { // delegate int RawFormatterSerialize(ref byte[] bytes, int offset, object value, IFormatterResolver formatterResolver); var serialize = GetMethod(type, new Type[] { typeof(byte[]).MakeByRefType(), typeof(int), null, typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(byte[]).MakeByRefType(), "bytes"); var param2 = Expression.Parameter(typeof(int), "offset"); var param3 = Expression.Parameter(typeof(object), "value"); var param4 = Expression.Parameter(typeof(IFormatterResolver), "formatterResolver"); var body = Expression.Call( param0, serialize, param1, param2, ti.IsValueType ? Expression.Unbox(param3, type) : Expression.Convert(param3, type), param4); var lambda = Expression.Lambda <RawFormatterSerialize>(body, param0, param1, param2, param3, param4).Compile(); this.serialize5 = lambda; } { // public static T Deserialize<T>(byte[] bytes) var deserialize = GetMethod(type, new Type[] { typeof(byte[]) }); var param1 = Expression.Parameter(typeof(byte[]), "bytes"); var body = Expression.Convert(Expression.Call(param0, deserialize, param1), typeof(object)); var lambda = Expression.Lambda <Func <MessagePackSerializer, byte[], object> >(body, param0, param1).Compile(); this.deserialize1 = lambda; } { // public static T Deserialize<T>(byte[] bytes, IFormatterResolver resolver) var deserialize = GetMethod(type, new Type[] { typeof(byte[]), typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(byte[]), "bytes"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var body = Expression.Convert(Expression.Call(param0, deserialize, param1, param2), typeof(object)); var lambda = Expression.Lambda <Func <MessagePackSerializer, byte[], IFormatterResolver, object> >(body, param0, param1, param2).Compile(); this.deserialize2 = lambda; } { // public static T Deserialize<T>(Stream stream) var deserialize = GetMethod(type, new Type[] { typeof(Stream) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var body = Expression.Convert(Expression.Call(param0, deserialize, param1), typeof(object)); var lambda = Expression.Lambda <Func <MessagePackSerializer, Stream, object> >(body, param0, param1).Compile(); this.deserialize3 = lambda; } { // public static T Deserialize<T>(Stream stream, IFormatterResolver resolver) var deserialize = GetMethod(type, new Type[] { typeof(Stream), typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var body = Expression.Convert(Expression.Call(param0, deserialize, param1, param2), typeof(object)); var lambda = Expression.Lambda <Func <MessagePackSerializer, Stream, IFormatterResolver, object> >(body, param0, param1, param2).Compile(); this.deserialize4 = lambda; } { // public static T Deserialize<T>(Stream stream, bool readStrict) var deserialize = GetMethod(type, new Type[] { typeof(Stream), typeof(bool) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(bool), "readStrict"); var body = Expression.Convert(Expression.Call(param0, deserialize, param1, param2), typeof(object)); var lambda = Expression.Lambda <Func <MessagePackSerializer, Stream, bool, object> >(body, param0, param1, param2).Compile(); this.deserialize5 = lambda; } { // public static T Deserialize<T>(Stream stream, IFormatterResolver resolver, bool readStrict) var deserialize = GetMethod(type, new Type[] { typeof(Stream), typeof(IFormatterResolver), typeof(bool) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var param3 = Expression.Parameter(typeof(bool), "readStrict"); var body = Expression.Convert(Expression.Call(param0, deserialize, param1, param2, param3), typeof(object)); var lambda = Expression.Lambda <Func <MessagePackSerializer, Stream, IFormatterResolver, bool, object> >(body, param0, param1, param2, param3).Compile(); this.deserialize6 = lambda; } { // public static T Deserialize<T>(ArraySegment<byte> bytes) var deserialize = GetMethod(type, new Type[] { typeof(ArraySegment <byte>) }); var param1 = Expression.Parameter(typeof(ArraySegment <byte>), "bytes"); var body = Expression.Convert(Expression.Call(param0, deserialize, param1), typeof(object)); var lambda = Expression.Lambda <Func <MessagePackSerializer, ArraySegment <byte>, object> >(body, param0, param1).Compile(); this.deserialize7 = lambda; } { // public static T Deserialize<T>(ArraySegment<byte> bytes, IFormatterResolver resolver) var deserialize = GetMethod(type, new Type[] { typeof(ArraySegment <byte>), typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(ArraySegment <byte>), "bytes"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var body = Expression.Convert(Expression.Call(param0, deserialize, param1, param2), typeof(object)); var lambda = Expression.Lambda <Func <MessagePackSerializer, ArraySegment <byte>, IFormatterResolver, object> >(body, param0, param1, param2).Compile(); this.deserialize8 = lambda; } { // public static T Deserialize<T>(byte[] bytes, int offset, IFormatterResolver resolver, out int readSize) var deserialize = GetMethod(type, new Type[] { typeof(byte[]), typeof(int), typeof(IFormatterResolver), typeof(int).MakeByRefType() }); var param1 = Expression.Parameter(typeof(byte[]), "bytes"); var param2 = Expression.Parameter(typeof(int), "offset"); var param3 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var param4 = Expression.Parameter(typeof(int).MakeByRefType(), "readSize"); var body = Expression.Convert(Expression.Call(param0, deserialize, param1, param2, param3, param4), typeof(object)); var lambda = Expression.Lambda <RawFormatterDeserialize>(body, param0, param1, param2, param3, param4).Compile(); this.deserialize9 = lambda; } }
public CompiledMethods(Type type) { { // public static byte[] Serialize<T>(T obj) var serialize = GetMethod(type, new Type[] { null }); var param1 = Expression.Parameter(typeof(object), "obj"); var body = Expression.Call(serialize, type.IsValueType ? Expression.Unbox(param1, type) : Expression.Convert(param1, type)); var lambda = Expression.Lambda <Func <object, byte[]> >(body, param1).Compile(); this.serialize1 = lambda; } { // public static byte[] Serialize<T>(T obj, IFormatterResolver resolver) var serialize = GetMethod(type, new Type[] { null, typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(object), "obj"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "formatterResolver"); var body = Expression.Call(serialize, type.IsValueType ? Expression.Unbox(param1, type) : Expression.Convert(param1, type), param2); var lambda = Expression.Lambda <Func <object, IFormatterResolver, byte[]> >(body, param1, param2).Compile(); this.serialize2 = lambda; } { // public static IOwnedBuffer<byte> SerializeSafe<T>(T obj) var serialize = GetSafeMethod(type, new Type[] { null }); var param1 = Expression.Parameter(typeof(object), "obj"); var body = Expression.Call(serialize, type.IsValueType ? Expression.Unbox(param1, type) : Expression.Convert(param1, type)); var lambda = Expression.Lambda <Func <object, IOwnedBuffer <byte> > >(body, param1).Compile(); this.serialize3 = lambda; } { // public static IOwnedBuffer<byte> SerializeSafe<T>(T obj, IFormatterResolver resolver) var serialize = GetSafeMethod(type, new Type[] { null, typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(object), "obj"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "formatterResolver"); var body = Expression.Call(serialize, type.IsValueType ? Expression.Unbox(param1, type) : Expression.Convert(param1, type), param2); var lambda = Expression.Lambda <Func <object, IFormatterResolver, IOwnedBuffer <byte> > >(body, param1, param2).Compile(); this.serialize4 = lambda; } { // public static IOwnedBuffer<byte> SerializeUnsafe<T>(T obj) var serialize = GetUnsafeMethod(type, new Type[] { null }); var param1 = Expression.Parameter(typeof(object), "obj"); var body = Expression.Call(serialize, type.IsValueType ? Expression.Unbox(param1, type) : Expression.Convert(param1, type)); var lambda = Expression.Lambda <Func <object, IOwnedBuffer <byte> > >(body, param1).Compile(); this.serialize5 = lambda; } { // public static IOwnedBuffer<byte> SerializeUnsafe<T>(T obj, IFormatterResolver resolver) var serialize = GetUnsafeMethod(type, new Type[] { null, typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(object), "obj"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "formatterResolver"); var body = Expression.Call(serialize, type.IsValueType ? Expression.Unbox(param1, type) : Expression.Convert(param1, type), param2); var lambda = Expression.Lambda <Func <object, IFormatterResolver, IOwnedBuffer <byte> > >(body, param1, param2).Compile(); this.serialize6 = lambda; } //{ // // public static void Serialize<T>(IArrayBufferWriter<byte> output, T obj) // var serialize = GetMethod(type, new Type[] { typeof(IArrayBufferWriter<byte>), null }); // var param1 = Expression.Parameter(typeof(IArrayBufferWriter<byte>), "output"); // var param2 = Expression.Parameter(typeof(object), "obj"); // var body = Expression.Call(serialize, param1, type.IsValueType // ? Expression.Unbox(param2, type) // : Expression.Convert(param2, type)); // var lambda = Expression.Lambda<Action<IArrayBufferWriter<byte>, object>>(body, param1, param2).Compile(); // this.serialize7 = lambda; //} //{ // // public static void Serialize<T>(IArrayBufferWriter<byte> output, T obj, IFormatterResolver resolver) // var serialize = GetMethod(type, new Type[] { typeof(IArrayBufferWriter<byte>), null, typeof(IFormatterResolver) }); // var param1 = Expression.Parameter(typeof(IArrayBufferWriter<byte>), "output"); // var param2 = Expression.Parameter(typeof(object), "obj"); // var param3 = Expression.Parameter(typeof(IFormatterResolver), "formatterResolver"); // var body = Expression.Call(serialize, param1, type.IsValueType // ? Expression.Unbox(param2, type) // : Expression.Convert(param2, type), param3); // var lambda = Expression.Lambda<Action<IArrayBufferWriter<byte>, object, IFormatterResolver>>(body, param1, param2, param3).Compile(); // this.serialize8 = lambda; //} { // public static void Serialize<T>(Stream stream, T obj) var serialize = GetMethod(type, new Type[] { typeof(Stream), null }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(object), "obj"); var body = Expression.Call(serialize, param1, type.IsValueType ? Expression.Unbox(param2, type) : Expression.Convert(param2, type)); var lambda = Expression.Lambda <Action <Stream, object> >(body, param1, param2).Compile(); this.serialize9 = lambda; } { // public static void Serialize<T>(Stream stream, T obj, IFormatterResolver resolver) var serialize = GetMethod(type, new Type[] { typeof(Stream), null, typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(object), "obj"); var param3 = Expression.Parameter(typeof(IFormatterResolver), "formatterResolver"); var body = Expression.Call(serialize, param1, type.IsValueType ? Expression.Unbox(param2, type) : Expression.Convert(param2, type), param3); var lambda = Expression.Lambda <Action <Stream, object, IFormatterResolver> >(body, param1, param2, param3).Compile(); this.serialize10 = lambda; } { // public static void Serialize<T>(ref MessagePackWriter writer, ref int idx, T obj, IFormatterResolver resolver) var serialize = GetMethod(type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), typeof(int).MakeByRefType(), null, typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(MessagePackWriter).MakeByRefType(), "writer"); var param2 = Expression.Parameter(typeof(int).MakeByRefType(), "idx"); var param3 = Expression.Parameter(typeof(object), "obj"); var param4 = Expression.Parameter(typeof(IFormatterResolver), "formatterResolver"); var body = Expression.Call(serialize, param1, param2, type.IsValueType ? Expression.Unbox(param3, type) : Expression.Convert(param3, type), param4); var lambda = Expression.Lambda <RawFormatterSerialize>(body, param1, param2, param3, param4).Compile(); this.serialize11 = lambda; } { // public static T Deserialize<T>(ReadOnlySpan<byte> bytes) var deserialize = GetMethod(type, new Type[] { typeof(ReadOnlySpan <byte>) }); var param1 = Expression.Parameter(typeof(ReadOnlySpan <byte>), "bytes"); var body = Expression.Convert(Expression.Call(deserialize, param1), typeof(object)); var lambda = Expression.Lambda <DeserializeSpan>(body, param1).Compile(); this.deserialize1 = lambda; } { // public static T Deserialize<T>(ReadOnlySpan<byte> bytes, IFormatterResolver resolver) var deserialize = GetMethod(type, new Type[] { typeof(ReadOnlySpan <byte>), typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(ReadOnlySpan <byte>), "bytes"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var body = Expression.Convert(Expression.Call(deserialize, param1, param2), typeof(object)); var lambda = Expression.Lambda <DeserializeSpanWithResolver>(body, param1, param2).Compile(); this.deserialize2 = lambda; } { // public static T Deserialize<T>(ReadOnlySequence<byte> sequence) var deserialize = GetMethod(type, new Type[] { typeof(ReadOnlySequence <byte>) }); var param1 = Expression.Parameter(typeof(ReadOnlySequence <byte>), "sequence"); var body = Expression.Convert(Expression.Call(deserialize, param1), typeof(object)); var lambda = Expression.Lambda <DeserializeSequence>(body, param1).Compile(); this.deserialize3 = lambda; } { // public static T Deserialize<T>(ReadOnlySequence<byte> sequence, IFormatterResolver resolver) var deserialize = GetMethod(type, new Type[] { typeof(ReadOnlySequence <byte>), typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(ReadOnlySequence <byte>), "sequence"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var body = Expression.Convert(Expression.Call(deserialize, param1, param2), typeof(object)); var lambda = Expression.Lambda <DeserializeSequenceWithResolver>(body, param1, param2).Compile(); this.deserialize4 = lambda; } { // public static T Deserialize<T>(Stream stream) var deserialize = GetMethod(type, new Type[] { typeof(Stream) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var body = Expression.Convert(Expression.Call(deserialize, param1), typeof(object)); var lambda = Expression.Lambda <Func <Stream, object> >(body, param1).Compile(); this.deserialize5 = lambda; } { // public static T Deserialize<T>(Stream stream, IFormatterResolver resolver) var deserialize = GetMethod(type, new Type[] { typeof(Stream), typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var body = Expression.Convert(Expression.Call(deserialize, param1, param2), typeof(object)); var lambda = Expression.Lambda <Func <Stream, IFormatterResolver, object> >(body, param1, param2).Compile(); this.deserialize6 = lambda; } { // public static T Deserialize<T>(Stream stream, bool readStrict) var deserialize = GetMethod(type, new Type[] { typeof(Stream), typeof(bool) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(bool), "readStrict"); var body = Expression.Convert(Expression.Call(deserialize, param1, param2), typeof(object)); var lambda = Expression.Lambda <Func <Stream, bool, object> >(body, param1, param2).Compile(); this.deserialize7 = lambda; } { // public static T Deserialize<T>(Stream stream, IFormatterResolver resolver, bool readStrict) var deserialize = GetMethod(type, new Type[] { typeof(Stream), typeof(IFormatterResolver), typeof(bool) }); var param1 = Expression.Parameter(typeof(Stream), "stream"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var param3 = Expression.Parameter(typeof(bool), "readStrict"); var body = Expression.Convert(Expression.Call(deserialize, param1, param2, param3), typeof(object)); var lambda = Expression.Lambda <Func <Stream, IFormatterResolver, bool, object> >(body, param1, param2, param3).Compile(); this.deserialize8 = lambda; } { // public static T Deserialize<T>(ref MessagePackReader reader, IFormatterResolver resolver) var deserialize = GetMethod(type, new Type[] { typeof(MessagePackReader).MakeByRefType(), typeof(IFormatterResolver) }); var param1 = Expression.Parameter(typeof(MessagePackReader).MakeByRefType(), "reader"); var param2 = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var body = Expression.Convert(Expression.Call(deserialize, param1, param2), typeof(object)); var lambda = Expression.Lambda <RawFormatterDeserialize>(body, param1, param2).Compile(); this.deserialize9 = lambda; } }