Example #1
0
        private ConverterSet RegisterNullableType <T>()
            where T : struct
        {
            var underlyingTypeConverter = GetConverterSet(typeof(T));

            if (underlyingTypeConverter == null)
            {
                throw new ArgumentException("Cannot find underlying type converter. Type=" + typeof(T).Name);
            }

            Func <T?, RedisValue> toFunc =
                o => o == null
                         ? RedisValue.Null
                         : ((Func <T, RedisValue>)underlyingTypeConverter.ToRedisValueFunc)(o.Value);

            Func <RedisValue, T?> fromFunc =
                o => o.IsNull
                         ? null
                         : (T?)((Func <RedisValue, T>)underlyingTypeConverter.FromRedisValueFunc)(o);

            var cs = new ConverterSet
            {
                ToRedisValueFunc         = toFunc,
                FromRedisValueFunc       = fromFunc,
                ObjectToRedisValueFunc   = RedisTypeConverterHelper.ConvertToObjectToFunc(toFunc),
                ObjectFromRedisValueFunc = RedisTypeConverterHelper.ConvertToObjectFromFunc(fromFunc),
            };

            lock (_converterMap)
            {
                _converterMap[typeof(T?)] = cs;
                return(cs);
            }
        }
 public MapperContext()
 {
     Cache  = new CacheSet();
     Naming = new NamingSettings(Cache);
     QualifiedMemberFactory = new QualifiedMemberFactory(this);
     RootMembersSource      = new RootMembersSource(QualifiedMemberFactory);
     ObjectMapperFactory    = new ObjectMapperFactory(Cache);
     UserConfigurations     = new UserConfigurationSet(this);
     ConstructionFactory    = new ComplexTypeConstructionFactory(Cache);
     ValueConverters        = new ConverterSet(UserConfigurations);
     RuleSets = MappingRuleSetCollection.Default;
 }
Example #3
0
 public MapperContext(NamingSettings namingSettings = null)
 {
     Cache               = new CacheSet();
     DataSources         = new DataSourceFinder();
     NamingSettings      = namingSettings ?? new NamingSettings();
     RootMembersSource   = new RootMembersSource(new RootQualifiedMemberFactory(this));
     ObjectMapperFactory = new ObjectMapperFactory(this);
     ObjectFlattener     = new ObjectFlattener();
     DerivedTypes        = new DerivedTypesCache();
     UserConfigurations  = new UserConfigurationSet();
     ValueConverters     = new ConverterSet();
     RuleSets            = new MappingRuleSetCollection();
 }
Example #4
0
        public void Register <T>(Func <T, RedisValue> toRedisValueFunc,
                                 Func <RedisValue, T> fromRedisValueFunc)
        {
            var cs = new ConverterSet
            {
                ToRedisValueFunc         = toRedisValueFunc,
                FromRedisValueFunc       = fromRedisValueFunc,
                ObjectToRedisValueFunc   = RedisTypeConverterHelper.ConvertToObjectToFunc(toRedisValueFunc),
                ObjectFromRedisValueFunc = RedisTypeConverterHelper.ConvertToObjectFromFunc(fromRedisValueFunc),
            };

            lock (_converterMap)
            {
                _converterMap[typeof(T)] = cs;
            }
        }
Example #5
0
        public void Register(Type type,
                             Func <object, RedisValue> toRedisValueFunc,
                             Func <RedisValue, object> fromRedisValueFunc)
        {
            var cs = new ConverterSet
            {
                ToRedisValueFunc         = RedisTypeConverterHelper.ConvertToToFunc(type, toRedisValueFunc),
                FromRedisValueFunc       = RedisTypeConverterHelper.ConvertToFromFunc(type, fromRedisValueFunc),
                ObjectToRedisValueFunc   = toRedisValueFunc,
                ObjectFromRedisValueFunc = fromRedisValueFunc,
            };

            lock (_converterMap)
            {
                _converterMap[type] = cs;
            }
        }
Example #6
0
        private ConverterSet RegisterWithJsonSerialization <T>()
        {
            Func <T, RedisValue> toFunc   = v => JsonConvert.SerializeObject(v, _jsonSerializerSettings);
            Func <RedisValue, T> fromFunc = o => JsonConvert.DeserializeObject <T>(o, _jsonSerializerSettings);

            var cs = new ConverterSet
            {
                ToRedisValueFunc         = toFunc,
                FromRedisValueFunc       = fromFunc,
                ObjectToRedisValueFunc   = RedisTypeConverterHelper.ConvertToObjectToFunc(toFunc),
                ObjectFromRedisValueFunc = RedisTypeConverterHelper.ConvertToObjectFromFunc(fromFunc),
            };

            lock (_converterMap)
            {
                _converterMap[typeof(T)] = cs;
                return(cs);
            }
        }