RoboZhando/Redis/Serialize/RedisConvert.cs
/// <summary>
/// Gets the serializer for the given type.
/// </summary>
/// <param name="type"></param>
/// <param name="options"></param>
/// <param name="property"></param>
/// <returns></returns>
Gets the serializer for the given type.
Gets the serializer for the given type .
public RedisSerializer GetSerializerForType(Type type, RedisOptionAttribute options = null, RedisPropertyAttribute property = null)
        {
            if (options != null && options.Serializer != null)
                return (RedisSerializer)Activator.CreateInstance(options.Serializer);
            if (property != null && property.Serializer != null)
                return (RedisSerializer)Activator.CreateInstance(property.Serializer);
            if (type.IsPrimitive || type.IsEnum || type == typeof(string))
                return new PrimitiveSerializer();
            if (type.IsGenericType)
            {
                if (type.GetGenericTypeDefinition() == typeof(Dictionary<,>))
                    return new DictionarySerializer();
                if (type.GetGenericTypeDefinition() == typeof(HashSet<>))
                    return new HashSetSerializer();
                if (type.GetGenericTypeDefinition() == typeof(List<>))
                    return new ListSerializer();
            }
            return new ClassSerializer();
        }
public RedisSerializer GetSerializerForType ( Type type , RedisOptionAttribute options = null , RedisPropertyAttribute property = null ) { if ( options != null && options . Serializer != null ) return ( RedisSerializer ) Activator . CreateInstance ( options . Serializer ) ; if ( property != null && property . Serializer != null ) return ( RedisSerializer ) Activator . CreateInstance ( property . Serializer ) ; if ( type . IsPrimitive || type . IsEnum || type == typeof ( string ) ) return new PrimitiveSerializer ( ) ; if ( type . IsGenericType ) { if ( type . GetGenericTypeDefinition ( ) == typeof ( Dictionary < , > ) ) return new DictionarySerializer ( ) ; if ( type . GetGenericTypeDefinition ( ) == typeof ( HashSet < > ) ) return new HashSetSerializer ( ) ; if ( type . GetGenericTypeDefinition ( ) == typeof ( List < > ) ) return new ListSerializer ( ) ; } return new ClassSerializer ( ) ; }
Gets the serializer for the given type.
Gets the serializer for the given type .
None
type
Type
None
options
RedisOptionAttribute
None
property
RedisPropertyAttribute
None