Esempio n. 1
0
        public ReflectedType(Type type)
        {
            UnderlyingType = type;
            TypeName       = type.GetFriendlyName();
            FullTypeName   = type.FullName;
            var interfaceType = Reflector.GetInterface(type);

            if (interfaceType != null)
            {
                InterfaceType     = interfaceType;
                InterfaceTypeName = interfaceType.FullName;
            }
            IsArray      = type.IsArray;
            IsList       = Reflector.IsList(type);
            IsDictionary = Reflector.IsDictionary(type);
            IsSimpleList = Reflector.IsSimpleList(type);
            IsDataEntity = Reflector.IsDataEntity(type) || (!Reflector.IsSimpleType(type) && !IsArray && !IsList && !IsDictionary);
            Type elementType;

            IsDataEntityList = Reflector.IsDataEntityList(type, out elementType);
            ElementType      = elementType;
            if (IsDataEntityList)
            {
                IsPolymorphicList = elementType != null && elementType.IsAbstract && (!elementType.IsInterface || !Reflector.IsDataEntity(elementType));
                IsListInterface   = type.GetGenericTypeDefinition() == typeof(IList <>);
            }
            IsSimpleType      = Reflector.IsSimpleType(type);
            IsNullableType    = Reflector.IsNullableType(type);
            IsMarkerInterface = Reflector.IsMarkerInterface(type);
            HashCode          = type.GetHashCode();
            IsGenericType     = type.IsGenericType;
            IsInterface       = type.IsInterface;
            IsAnonymous       = Reflector.IsAnonymousType(type);
            IsEmitted         = Reflector.IsEmitted(type);
        }
Esempio n. 2
0
        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;
                                }
                            }
                        }
                    }
                }
            }
        }