Esempio n. 1
0
        //===============================================================================================
        //
        //===============================================================================================


        private static ISerializer GetSerializer(Type type, ISerializer serializer)
        {
            if (serializer != null)
            {
                return(serializer);
            }

            serializer = SerializerRegistry.GetSerializer(type);
            if (serializer != null)
            {
                return(serializer);
            }


            if (type.IsGenericType)
            {
                serializer = SerializerRegistry.GetSerializer(type.GetGenericTypeDefinition());
                if (serializer != null)
                {
                    return(serializer);
                }
            }

            if (type.IsEnum)
            {
                return(SerializerRegistry.GetSerializer(typeof(Enum)));
            }

            if (type.IsClass && serializer == null)
            {
                return(SerializerRegistry.GetSerializer(typeof(object)));
            }

            return(null);
        }
Esempio n. 2
0
        //===============================================================================================
        //
        //===============================================================================================


        private static ISerializer GetSerializer(Type type, ISerializer serializer)
        {
            if (serializer != null)
            {
                return(serializer);
            }

            serializer = SerializerRegistry.GetSerializer(type);
            if (serializer != null)
            {
                return(serializer);
            }

            var nullableUnderlyingType = Nullable.GetUnderlyingType(type);

            if (nullableUnderlyingType != null)
            {
                return(SerializerRegistry.GetNullableSerializer());
            }

            if (type.IsGenericType)
            {
                serializer = SerializerRegistry.GetSerializer(type.GetGenericTypeDefinition());
                if (serializer != null)
                {
                    return(serializer);
                }
            }

            if (type.IsArray)
            {
                serializer = SerializerRegistry.GetSerializer(typeof(Array));
                if (serializer != null)
                {
                    return(serializer);
                }
            }

            if (type.IsEnum)
            {
                return(SerializerRegistry.GetSerializer(typeof(Enum)));
            }

            if (type.IsClass && serializer == null)
            {
                return(SerializerRegistry.GetSerializer(typeof(object)));
            }

            return(null);
        }