Beispiel #1
0
        static NullableMessagePackSerializer()
        {
            NullableMessagePackSerializer <T> ._nullableTHasValueProperty = NullableMessagePackSerializer <T> .GetOnlyWhenNullable <PropertyInfo>(typeof(Nullable <>).MakeGenericType(new Type[] { Nullable.GetUnderlyingType(typeof(T)) }).GetProperty("HasValue"));

            NullableMessagePackSerializer <T> ._nullableTValueProperty = NullableMessagePackSerializer <T> .GetOnlyWhenNullable <PropertyInfo>(typeof(Nullable <>).MakeGenericType(new Type[] { Nullable.GetUnderlyingType(typeof(T)) }).GetProperty("Value"));

            NullableMessagePackSerializer <T> ._nullableTImplicitOperator = NullableMessagePackSerializer <T> .GetOnlyWhenNullable <MethodInfo>(typeof(Nullable <>).MakeGenericType(new Type[] { Nullable.GetUnderlyingType(typeof(T)) }).GetMethod("op_Implicit", new Type[] { Nullable.GetUnderlyingType(typeof(T)) }));
        }
Beispiel #2
0
        internal NullableMessagePackSerializer(SerializationContext context, EmitterFlavor emitterFlavor)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (NullableMessagePackSerializer <T> ._nullableTImplicitOperator == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "'{0}' is not nullable type.", new object[] { typeof(T) }));
            }
            SerializerEmitter emitter = SerializationMethodGeneratorManager.Get().CreateEmitter(typeof(T), emitterFlavor);

            NullableMessagePackSerializer <T> .CreatePacking(emitter);

            NullableMessagePackSerializer <T> .CreateUnpacking(emitter);

            this._underlying = emitter.CreateInstance <T>(context);
        }