コード例 #1
0
 public ServerLoginAction(IRoomMapper roomMapper, IUserRepository userRepository,
                          IRoomRepository roomRepository, IDictionaryConverter <IActionBag> bagConverter) : base(bagConverter)
 {
     _roomMapper     = roomMapper;
     _userRepository = userRepository;
     _roomRepository = roomRepository;
 }
コード例 #2
0
 public ServerRegisterAction(IUserRepository userRepository, IUserFactory userFactory,
                             IDictionaryConverter <IActionBag> bagConverter)
     : base(bagConverter)
 {
     _userRepository = userRepository;
     _userFactory    = userFactory;
 }
コード例 #3
0
        public void Should_map_an_anonymous_object_to_the_settings()
        {
            var converterCache = new DynamicObjectConverterCache(new DynamicImplementationBuilder());
            var cache          = new DictionaryConverterCache();

            var source = new
            {
                Host        = "localhost",
                VirtualHost = "vortex",
                Username    = "******",
                Password    = "******",
                Port        = 5672,
            };

            IDictionaryConverter         converter  = cache.GetConverter(source.GetType());
            IDictionary <string, object> dictionary = converter.GetDictionary(source);

            IObjectConverter objectConverter = converterCache.GetConverter(typeof(RabbitMqSettings));

            var settings = (RabbitMqSettings)objectConverter.GetObject(dictionary);

            Assert.IsNotNull(settings);

            Assert.AreEqual("localhost", settings.Host);
            Assert.AreEqual("vortex", settings.VirtualHost);
            Assert.AreEqual("joe", settings.Username);
            Assert.AreEqual("guess", settings.Password);
            Assert.AreEqual(5672, settings.Port);
            Assert.AreEqual(0, settings.Heartbeat);

            Assert.IsNull(settings.Options);
        }
コード例 #4
0
        public void ConvertWithIndexEndTest()
        {
            var config = new CsvConfiguration {
                HasHeaderRecord = false
            };
            var rowMock       = new Mock <ICsvReaderRow>();
            var headers       = new[] { "Id", "Name", "Prop1", "Prop2", "Prop3" };
            var currentRecord = new[] { "1", "One", "1", "2", "3" };

            rowMock.Setup(m => m.Configuration).Returns(config);
            rowMock.Setup(m => m.FieldHeaders).Returns(headers);
            rowMock.Setup(m => m.CurrentRecord).Returns(currentRecord);
            rowMock.Setup(m => m.GetField(It.IsAny <int>())).Returns <int>(index => currentRecord[index]);
            var data = new CsvPropertyMapData(typeof(Test).GetProperty("Dictionary"))
            {
                Index    = 2,
                IndexEnd = 3
            };

            data.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture;

            var converter  = new IDictionaryConverter();
            var dictionary = (IDictionary)converter.ConvertFromString("1", rowMock.Object, data);

            Assert.AreEqual(2, dictionary.Count);
            Assert.AreEqual("1", dictionary["Prop1"]);
            Assert.AreEqual("2", dictionary["Prop2"]);
        }
コード例 #5
0
        public void Setup()
        {
            var factory = new DictionaryConverterCache();

            IDictionaryConverter converter = factory.GetConverter(typeof(ValuesImpl));

            _expected   = new ValuesImpl("Hello", 27, new DateTime(2012, 10, 1), null, 123.45m);
            _dictionary =
                converter.GetDictionary(_expected);
        }
コード例 #6
0
ファイル: Map.cs プロジェクト: mathiasfk/elephant
 public Map(Func <TValue> valueFactory, IDictionaryConverter <TValue> dictionaryConverter, ConcurrentDictionary <TKey, TValue> internalDictionary, TimeSpan expirationScanInterval = default)
 {
     ValueFactory            = valueFactory ?? throw new ArgumentNullException(nameof(valueFactory));
     DictionaryConverter     = dictionaryConverter ?? throw new ArgumentNullException(nameof(dictionaryConverter));
     InternalDictionary      = internalDictionary ?? throw new ArgumentNullException(nameof(internalDictionary));
     KeyExpirationDictionary = new ConcurrentDictionary <TKey, DateTimeOffset>();
     if (expirationScanInterval <= TimeSpan.Zero)
     {
         expirationScanInterval = TimeSpan.FromSeconds(30);
     }
     _expirationTimerIntervalMs = expirationScanInterval.TotalMilliseconds;
     _expirationTimer           = new Timer(_expirationTimerIntervalMs);
     _expirationTimer.Elapsed  += RemoveExpiredKeys;
 }
コード例 #7
0
ファイル: Map.cs プロジェクト: mathiasfk/elephant
 public Map(Func <TValue> valueFactory, IDictionaryConverter <TValue> dictionaryConverter, TimeSpan expirationScanInterval = default)
     : this(valueFactory, dictionaryConverter, new ConcurrentDictionary <TKey, TValue>(), expirationScanInterval)
 {
 }
コード例 #8
0
ファイル: Map.cs プロジェクト: mathiasfk/elephant
 public Map(IDictionaryConverter <TValue> dictionaryConverter, TimeSpan expirationScanInterval = default)
     : this(() => (TValue)Activator.CreateInstance(typeof(TValue)), dictionaryConverter, expirationScanInterval)
 {
 }
コード例 #9
0
ファイル: Map.cs プロジェクト: lulzzz/elephant
 public Map(Func <TValue> valueFactory, IDictionaryConverter <TValue> dictionaryConverter, ConcurrentDictionary <TKey, TValue> internalDictionary)
 {
     ValueFactory        = valueFactory ?? throw new ArgumentNullException(nameof(valueFactory));
     DictionaryConverter = dictionaryConverter ?? throw new ArgumentNullException(nameof(dictionaryConverter));
     InternalDictionary  = internalDictionary ?? throw new ArgumentNullException(nameof(internalDictionary));
 }
コード例 #10
0
ファイル: DefaultConverter.cs プロジェクト: UruIT/rest-client
 private string NewPrefix(string propName, string key, IDictionaryConverter converter)
 {
     return(propName + (string.IsNullOrEmpty(key) ? string.Empty : (converter.GetSeparator() + key)));
 }
コード例 #11
0
 public ObjectDictionaryMapper(ReadOnlyProperty <T> property, IDictionaryConverter converter)
 {
     _property  = property;
     _converter = converter;
 }
コード例 #12
0
 public BlockLoggedUserHandler(IDictionaryConverter <IActionBag> bagConverter)
     : base(bagConverter)
 {
 }
コード例 #13
0
 protected AbstractHandler(IDictionaryConverter <IActionBag> bagConverter)
 {
     BagConverter = bagConverter;
 }
コード例 #14
0
 public BasicIncludeHandler(IDictionaryConverter <IActionBag> bagConverter)
     : base(bagConverter)
 {
 }
コード例 #15
0
        IDictionaryMapper <T> GetDictionaryMapper(ReadOnlyProperty <T> property, Type valueType)
        {
            Type underlyingType;

            if (valueType.IsNullable(out underlyingType))
            {
                Type converterType = typeof(NullableValueDictionaryMapper <,>).MakeGenericType(typeof(T),
                                                                                               underlyingType);

                return((IDictionaryMapper <T>)Activator.CreateInstance(converterType, property));
            }

            if (valueType.IsEnum)
            {
                return(new EnumDictionaryMapper <T>(property));
            }

            if (valueType.IsArray)
            {
                Type elementType = valueType.GetElementType();
                if (elementType.IsValueType || elementType == typeof(string))
                {
                    return(new ValueDictionaryMapper <T>(property));
                }

                IDictionaryConverter elementConverter = _cache.GetConverter(elementType);

                Type converterType = typeof(ObjectArrayDictionaryMapper <,>).MakeGenericType(typeof(T), elementType);
                return((IDictionaryMapper <T>)Activator.CreateInstance(converterType, property, elementConverter));
            }

            if (valueType.IsValueType || valueType == typeof(string))
            {
                return(new ValueDictionaryMapper <T>(property));
            }

            if (valueType.HasInterface(typeof(IEnumerable <>)))
            {
                Type elementType = valueType.GetClosingArguments(typeof(IEnumerable <>)).Single();

                if (valueType.ClosesType(typeof(IDictionary <,>)))
                {
                    Type[] arguments = valueType.GetClosingArguments(typeof(IDictionary <,>)).ToArray();
                    Type   keyType   = arguments[0];
                    if (keyType.IsValueType || keyType == typeof(string))
                    {
                        elementType = arguments[1];
                        if (elementType.IsValueType || elementType == typeof(string))
                        {
                            Type converterType =
                                typeof(ValueValueDictionaryDictionaryMapper <, ,>).MakeGenericType(typeof(T),
                                                                                                   keyType, elementType);
                            return((IDictionaryMapper <T>)Activator.CreateInstance(converterType, property));
                        }
                        else
                        {
                            Type converterType =
                                typeof(ValueObjectDictionaryDictionaryMapper <, ,>).MakeGenericType(typeof(T),
                                                                                                    keyType, elementType);
                            IDictionaryConverter elementConverter = _cache.GetConverter(elementType);
                            return
                                ((IDictionaryMapper <T>)Activator.CreateInstance(converterType, property, elementConverter));
                        }
                    }

                    throw new InvalidOperationException("Unable to map a reference type key dictionary");
                }

                if (valueType.ClosesType(typeof(IList <>)) || valueType.ClosesType(typeof(IEnumerable <>)))
                {
                    Type converterType = typeof(ObjectListDictionaryMapper <,>).MakeGenericType(typeof(T), elementType);
                    IDictionaryConverter elementConverter = _cache.GetConverter(elementType);

                    return((IDictionaryMapper <T>)Activator.CreateInstance(converterType, property, elementConverter));
                }
            }
            return(new ObjectDictionaryMapper <T>(property, _cache.GetConverter(valueType)));
        }
コード例 #16
0
ファイル: Map.cs プロジェクト: lulzzz/elephant
 public Map(IDictionaryConverter <TValue> dictionaryConverter)
     : this(() => (TValue)Activator.CreateInstance(typeof(TValue)), dictionaryConverter)
 {
 }
コード例 #17
0
ファイル: Map.cs プロジェクト: lulzzz/elephant
 public Map(Func <TValue> valueFactory, IDictionaryConverter <TValue> dictionaryConverter)
     : this(valueFactory, dictionaryConverter, new ConcurrentDictionary <TKey, TValue>())
 {
 }
コード例 #18
0
 public ObjectListDictionaryMapper(ReadOnlyProperty <T> property, IDictionaryConverter elementConverter)
 {
     _property         = property;
     _elementConverter = elementConverter;
 }
コード例 #19
0
        public IDictionarySerializer AddConverter(IDictionaryConverter converter)
        {
            this.converters.Add(converter);

            return(this);
        }