Exemplo n.º 1
0
 public bool TryGetValue(string key, out ReadWriteProperty <T> value)
 {
     try
     {
         return(_properties.TryGetValue(key, out value));
     }
     catch (KeyNotFoundException)
     {
         throw new KeyNotFoundException($"The read only property {key} was not found.");
     }
 }
Exemplo n.º 2
0
 public ValueListObjectMapper(ReadWriteProperty <T> property)
 {
     _property = property;
 }
Exemplo n.º 3
0
 public bool TryGetProperty(string propertyName, out ReadWriteProperty <T> property)
 {
     return(_properties.TryGetValue(propertyName, out property));
 }
Exemplo n.º 4
0
 public ValueValueDictionaryObjectMapper(ReadWriteProperty <T> property)
 {
     _property = property;
 }
Exemplo n.º 5
0
        IObjectMapper <TImplementation> GetDictionaryToObjectConverter(ReadWriteProperty <TImplementation> property,
                                                                       Type valueType)
        {
            var underlyingType = Nullable.GetUnderlyingType(valueType);

            if (underlyingType != null)
            {
                var converterType =
                    typeof(NullableValueObjectMapper <,>).MakeGenericType(typeof(TImplementation), underlyingType);

                return((IObjectMapper <TImplementation>)Activator.CreateInstance(converterType, property));
            }

            if (valueType.GetTypeInfo().IsEnum)
            {
                return(new EnumObjectMapper <TImplementation>(property));
            }

            if (valueType.IsArray)
            {
                var elementType = valueType.GetElementType();
                if (ValueObject.IsValueObjectType(elementType))
                {
                    var valueConverterType =
                        typeof(ValueArrayObjectMapper <,>).MakeGenericType(typeof(TImplementation), elementType);
                    return((IObjectMapper <TImplementation>)Activator.CreateInstance(valueConverterType, property));
                }

                var elementConverter = _cache.GetConverter(elementType);

                var converterType =
                    typeof(ObjectArrayObjectMapper <,>).MakeGenericType(typeof(TImplementation), elementType);
                return((IObjectMapper <TImplementation>)Activator.CreateInstance(converterType, property,
                                                                                 elementConverter));
            }

            if (ValueObject.IsValueObjectType(valueType))
            {
                return(new ValueObjectMapper <TImplementation>(property));
            }

            if (valueType.ClosesType(typeof(IEnumerable <>)))
            {
                if (valueType.ClosesType(typeof(IDictionary <,>)))
                {
                    Type[] genericArguments = valueType.GetClosingArguments(typeof(IDictionary <,>)).ToArray();

                    var keyType     = genericArguments[0];
                    var elementType = genericArguments[1];


                    if (ValueObject.IsValueObjectType(keyType))
                    {
                        if (ValueObject.IsValueObjectType(elementType))
                        {
                            var valueConverterType =
                                typeof(ValueValueDictionaryObjectMapper <, ,>).MakeGenericType(typeof(TImplementation),
                                                                                               keyType, elementType);
                            return((IObjectMapper <TImplementation>)Activator.CreateInstance(valueConverterType,
                                                                                             property));
                        }
                        else
                        {
                            var elementConverter   = _cache.GetConverter(elementType);
                            var valueConverterType =
                                typeof(ValueObjectDictionaryObjectMapper <, ,>).MakeGenericType(typeof(TImplementation),
                                                                                                keyType, elementType);
                            return((IObjectMapper <TImplementation>)Activator.CreateInstance(valueConverterType,
                                                                                             property, elementConverter));
                        }
                    }

                    throw new InvalidOperationException("A dictionary with a reference type key is not supported: " +
                                                        property.Property.Name);
                }


                if (valueType.ClosesType(typeof(IList <>)) || valueType.ClosesType(typeof(IEnumerable <>)))
                {
                    Type[] genericArguments = valueType.GetClosingArguments(typeof(IEnumerable <>)).ToArray();
                    var    elementType      = genericArguments[0];

                    if (ValueObject.IsValueObjectType(elementType))
                    {
                        var valueConverterType =
                            typeof(ValueListObjectMapper <,>).MakeGenericType(typeof(TImplementation), elementType);

                        return((IObjectMapper <TImplementation>)Activator.CreateInstance(valueConverterType, property));
                    }

                    var elementConverter = _cache.GetConverter(elementType);

                    var converterType =
                        typeof(ObjectListObjectMapper <,>).MakeGenericType(typeof(TImplementation), elementType);

                    return((IObjectMapper <TImplementation>)Activator.CreateInstance(converterType, property,
                                                                                     elementConverter));
                }
            }

            return(new ObjectObjectMapper <TImplementation>(property, _cache.GetConverter(valueType)));
        }
Exemplo n.º 6
0
 public EnumObjectMapper(ReadWriteProperty <T> property)
 {
     _property = property;
 }
Exemplo n.º 7
0
 public NullableValueObjectMapper(ReadWriteProperty <T> property)
 {
     _property = property;
 }
Exemplo n.º 8
0
 public ObjectListObjectMapper(ReadWriteProperty <T> property,
                               IObjectConverter converter)
 {
     _property  = property;
     _converter = converter;
 }
 public ValueObjectDictionaryObjectMapper(ReadWriteProperty <T> property, IObjectConverter valueConverter)
 {
     _property       = property;
     _valueConverter = valueConverter;
 }
Exemplo n.º 10
0
 public ValueObjectMapper(ReadWriteProperty <T> property)
 {
     _property      = property;
     _typeConverter = TypeDescriptor.GetConverter(property.Property.PropertyType);
 }
Exemplo n.º 11
0
 public ObjectObjectMapper(ReadWriteProperty <T> property, IObjectConverter converter)
 {
     _property      = property;
     _converter     = converter;
     _typeConverter = TypeDescriptor.GetConverter(property.Property.PropertyType);
 }