Ejemplo n.º 1
0
        public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None)
        {
            var colAttr = prop.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(ColumnAttribute));

            _prop = prop;
#if ENABLE_IL2CPP
            var ca = prop.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute;
            Name = ca == null ? prop.Name : ca.Name;
#else
            Name = (colAttr != null && colAttr.ConstructorArguments.Count > 0) ?
                   colAttr.ConstructorArguments[0].Value?.ToString() :
                   prop.Name;
#endif
            //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead
            ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
            Collation  = Orm.Collation(prop);

            IsPK = Orm.IsPK(prop) ||
                   (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) &&
                    string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0);

            var isAuto = Orm.IsAutoInc(prop) || (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK));
            IsAutoGuid  = isAuto && ColumnType == typeof(Guid);
            IsAutoInc   = isAuto && !IsAutoGuid;
            IsAutomatic = Orm.IsAutomatic(prop);

            Indices = Orm.GetIndices(prop);
            if (!Indices.Any() &&
                !IsPK &&
                ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) &&
                Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase)
                )
            {
                Indices = new IndexedAttribute[] { new IndexedAttribute() };
            }
            IsNullable      = !(IsPK || Orm.IsMarkedNotNull(prop));
            MaxStringLength = Orm.MaxStringLength(prop);

            StoreAsText = prop.PropertyType.GetTypeInfo().CustomAttributes.Any(x => x.AttributeType == typeof(StoreAsTextAttribute));
        }