internal static Tuple <Type, Type> GetTypeConverter(Type fromType, PropertyInfo property, IEntityMap entityMap) { if (entityMap != null) { var propertyMap = entityMap.Properties.FirstOrDefault(p => p.Property.PropertyName == property.Name); if (propertyMap != null) { var typeConverter = propertyMap.Property.Converter; if (typeConverter != null) { TypeConverterAttribute.ValidateTypeConverterType(typeConverter, fromType, property.PropertyType); return(Tuple.Create(typeConverter, TypeConverterAttribute.GetExpectedConverterInterfaceType(fromType, property.PropertyType))); } } } return(TypeConverterAttribute.GetTypeConverter(fromType, property)); }
public ReflectedProperty(PropertyInfo property, int position = -1, bool readAttributes = true) { PropertyName = property.Name; PropertyType = property.PropertyType; IsPersistent = true; IsSelectable = true; IsSerializable = true; IsBinary = property.PropertyType == typeof(byte[]); IsSimpleList = !IsBinary && Reflector.IsSimpleList(property.PropertyType); IsDataEntity = Reflector.IsDataEntity(property.PropertyType); Type elementType; IsDataEntityList = Reflector.IsDataEntityList(property.PropertyType, out elementType); ElementType = elementType; IsPolymorphicList = IsDataEntityList && elementType != null && elementType.IsAbstract && !elementType.IsInterface; if (IsDataEntityList) { IsList = true; IsListInterface = property.PropertyType.GetGenericTypeDefinition() == typeof(IList <>); } else { IsList = !IsBinary && Reflector.IsList(property.PropertyType); if (IsList) { ElementType = Reflector.GetElementType(property.PropertyType); IsListInterface = property.PropertyType.GetGenericTypeDefinition() == typeof(IList <>); } } IsSimpleType = !IsBinary && Reflector.IsSimpleType(property.PropertyType); IsNullableType = Reflector.IsNullableType(property.PropertyType); CanWrite = property.CanWrite; CanRead = property.CanRead; Position = position; IsObject = IsDataEntity || (property.PropertyType.IsClass && !IsSimpleType && !IsSimpleList && !IsBinary && !IsList); IsObjectList = IsDataEntityList || (IsList && ElementType != null && ElementType.IsClass && !Reflector.IsSimpleType(ElementType) && !Reflector.IsSimpleList(ElementType)); Converter = null; MappedColumnName = property.Name; if (readAttributes) { if (IsListInterface) { Sorted = property.GetCustomAttributes(typeof(SortedAttribute), false).Cast <SortedAttribute>().FirstOrDefault(); Distinct = property.GetCustomAttributes(typeof(DistinctAttribute), false).Cast <DistinctAttribute>().FirstOrDefault(); } MappedColumnName = MapColumnAttribute.GetMappedColumnName(property); MappedPropertyName = MapPropertyAttribute.GetMappedPropertyName(property); var typeConverter = TypeConverterAttribute.GetTypeConverter(property); if (typeConverter != null) { AddConverter(typeConverter.TypeConverterType); } var items = property.GetCustomAttributes(true).OfType <PropertyAttribute>(); foreach (var item in items) { var primaryKeyAttribute = item as PrimaryKeyAttribute; if (primaryKeyAttribute != null) { IsPrimaryKey = true; KeyPosition = primaryKeyAttribute.Position; } else { var generategAttribute = item as Generate.UsingAttribute; if (generategAttribute != null) { Generator = generategAttribute.Type; } else if (item is Generate.NativeAttribute) { IsAutoGenerated = true; } else { var referencesAttribute = item as ReferencesAttribute; if (referencesAttribute != null) { Parent = referencesAttribute.Parent; RefPosition = referencesAttribute.Position; } else { var parameterAttribute = item as ParameterAttribute; if (parameterAttribute != null) { ParameterName = parameterAttribute.Name; Direction = parameterAttribute.Direction; } else if (item is DoNotPersistAttribute) { IsPersistent = false; } else if (item is DoNotSelectAttribute) { IsSelectable = false; } else if (item is DoNotSerializeAttribute) { IsSerializable = false; } } } } } } }