public ServerLoginAction(IRoomMapper roomMapper, IUserRepository userRepository, IRoomRepository roomRepository, IDictionaryConverter <IActionBag> bagConverter) : base(bagConverter) { _roomMapper = roomMapper; _userRepository = userRepository; _roomRepository = roomRepository; }
public ServerRegisterAction(IUserRepository userRepository, IUserFactory userFactory, IDictionaryConverter <IActionBag> bagConverter) : base(bagConverter) { _userRepository = userRepository; _userFactory = userFactory; }
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); }
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"]); }
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); }
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; }
public Map(Func <TValue> valueFactory, IDictionaryConverter <TValue> dictionaryConverter, TimeSpan expirationScanInterval = default) : this(valueFactory, dictionaryConverter, new ConcurrentDictionary <TKey, TValue>(), expirationScanInterval) { }
public Map(IDictionaryConverter <TValue> dictionaryConverter, TimeSpan expirationScanInterval = default) : this(() => (TValue)Activator.CreateInstance(typeof(TValue)), dictionaryConverter, expirationScanInterval) { }
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)); }
private string NewPrefix(string propName, string key, IDictionaryConverter converter) { return(propName + (string.IsNullOrEmpty(key) ? string.Empty : (converter.GetSeparator() + key))); }
public ObjectDictionaryMapper(ReadOnlyProperty <T> property, IDictionaryConverter converter) { _property = property; _converter = converter; }
public BlockLoggedUserHandler(IDictionaryConverter <IActionBag> bagConverter) : base(bagConverter) { }
protected AbstractHandler(IDictionaryConverter <IActionBag> bagConverter) { BagConverter = bagConverter; }
public BasicIncludeHandler(IDictionaryConverter <IActionBag> bagConverter) : base(bagConverter) { }
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))); }
public Map(IDictionaryConverter <TValue> dictionaryConverter) : this(() => (TValue)Activator.CreateInstance(typeof(TValue)), dictionaryConverter) { }
public Map(Func <TValue> valueFactory, IDictionaryConverter <TValue> dictionaryConverter) : this(valueFactory, dictionaryConverter, new ConcurrentDictionary <TKey, TValue>()) { }
public ObjectListDictionaryMapper(ReadOnlyProperty <T> property, IDictionaryConverter elementConverter) { _property = property; _elementConverter = elementConverter; }
public IDictionarySerializer AddConverter(IDictionaryConverter converter) { this.converters.Add(converter); return(this); }