Exemplo n.º 1
0
        public SerializerPair GetOrCreateScalar(Type serializerType, bool instanceSerializer)
        {
            if (instanceSerializer && myScalars.CanBePolymorphic(serializerType))
            {
                return(myScalars.GetInstanceSerializer(serializerType));
            }

            if (!mySerializers.TryGetValue(serializerType, out var serializerPair))
            {
                try
                {
                    ReflectionUtil.InvokeGenericThis(this, nameof(RegisterScalar), serializerType);
                }
                catch (Exception e)
                {
                    throw new Exception($"Unable to create serializer for {e.Data[FirstChanceExceptionInterceptor.ExceptionDataKey]}. {e.Message}", e);
                }
                serializerPair = mySerializers[serializerType];
                if (serializerPair == null)
                {
                    Assertion.Fail($"Unable to Create serializer for scalar type {serializerType.ToString(true)}");
                }
                else
                {
                    Assertion.Assert(!serializerPair.IsPolymorphic, "Polymorphic serializer can't be stored in staticSerializers");
                }
                return(serializerPair);
            }

            return(serializerPair);
        }
Exemplo n.º 2
0
        public SerializerPair GetOrCreateScalar(Type serializerType, bool instanceSerializer)
        {
            if (instanceSerializer && myScalars.CanBePolymorphic(serializerType))
            {
                return(myScalars.GetInstanceSerializer(serializerType));
            }

            if (!mySerializers.TryGetValue(serializerType, out var serializerPair))
            {
                try
                {
                    ReflectionUtil.InvokeGenericThis(this, nameof(RegisterScalar), serializerType);
                }
                catch (Exception e)
                {
#if JET_MODE_ASSERT
                    throw new Exception($"Unable to create serializer for {string.Join(" -> ", myCurrentSerializersChain.Select(t => t.ToString(true)).ToArray())}. {e.Message}", e);
#else
                    throw new Exception($"Unable to create serializer for {serializerType.ToString(true)}. {e.Message}", e);
#endif
                }
                serializerPair = mySerializers[serializerType];
                if (serializerPair == null)
                {
                    Assertion.Fail($"Unable to Create serializer for scalar type {serializerType.ToString(true)}");
                }
                return(serializerPair);
            }

            return(serializerPair);
        }
        public SerializerPair GetOrCreateScalar(Type serializerType, bool instanceSerializer)
        {
            if (instanceSerializer && myScalars.CanBePolymorphic(serializerType))
            {
                return(GetPolymorphic(serializerType));
            }

            if (!mySerializers.TryGetValue(serializerType, out var serializerPair))
            {
                ReflectionUtil.InvokeGenericThis(this, nameof(RegisterScalar), serializerType);
                serializerPair = mySerializers[serializerType];
                if (serializerPair == null)
                {
                    Assertion.Fail($"Unable to Create serializer for scalar type {serializerType.ToString(true)}");
                }
                return(serializerPair);
            }

            return(serializerPair);
        }