예제 #1
0
        static memoryDatabaseModel()
        {
            Type type = typeof(valueType);

            Attribute = fastCSharp.code.typeAttribute.GetAttribute <memoryDatabaseModel>(type, true, true) ?? memoryDatabaseModel.Default;
            code.fieldIndex[] fieldArray = fastCSharp.code.memberIndexGroup <valueType> .GetFields(Attribute.MemberFilter);

            subArray <memoryDatabaseModel.fieldInfo> fields = new subArray <memoryDatabaseModel.fieldInfo>(), primaryKeys = new subArray <memoryDatabaseModel.fieldInfo>();

            memoryDatabaseModel.fieldInfo identity = default(memoryDatabaseModel.fieldInfo);
            int isCase = 0, isIdentity = 0;

            foreach (code.fieldIndex field in fieldArray)
            {
                Type memberType = field.Member.FieldType;
                if (!memberType.IsPointer && (!memberType.IsArray || memberType.GetArrayRank() == 1) && !field.IsIgnore)
                {
                    dataMember memberAttribute = field.GetAttribute <dataMember>(true, true) ?? dataMember.DefaultDataMember;
                    if (memberAttribute.IsSetup)
                    {
                        fields.Add(new memoryDatabaseModel.fieldInfo(field, memberAttribute));
                        MemberMap.SetMember(field.MemberIndex);
                        if (isIdentity == 0)
                        {
                            if (memberAttribute != null && memberAttribute.IsIdentity)
                            {
                                identity   = new memoryDatabaseModel.fieldInfo(field, memberAttribute);
                                isIdentity = 1;
                            }
                            else if (isCase == 0 && field.Member.Name == fastCSharp.config.memoryDatabase.Default.DefaultIdentityName)
                            {
                                identity = new memoryDatabaseModel.fieldInfo(field, memberAttribute);
                                isCase   = 1;
                            }
                            else if (identity.Field == null && field.Member.Name.ToLower() == fastCSharp.config.memoryDatabase.Default.DefaultIdentityName)
                            {
                                identity = new memoryDatabaseModel.fieldInfo(field, memberAttribute);
                            }
                        }
                        if (memberAttribute.PrimaryKeyIndex != 0)
                        {
                            primaryKeys.Add(new memoryDatabaseModel.fieldInfo(field, memberAttribute));
                        }
                    }
                }
            }
            IsAllMember = fields.length == fieldArray.Length ? 1 : 0;
            if ((Identity = identity).Field != null)
            {
#if NOJIT
                new sqlModel <valueType> .identity32(identity.Field).Get(out GetIdentity, out SetIdentity);
#else
                GetIdentity = getIdentityGetter32("GetMemoryDatabaseIdentity", identity.Field);
                SetIdentity = getIdentitySetter32("SetMemoryDatabaseIdentity", identity.Field);
#endif
            }
            PrimaryKeys = primaryKeys.ToArray();
        }
예제 #2
0
        /// <summary>
        /// 获取数据库成员信息
        /// </summary>
        /// <param name="member">成员信息</param>
        /// <returns>数据库成员信息</returns>
        internal static dataMember Get(memberIndex member)
        {
            dataMember value = member.GetAttribute <dataMember>(true, false);

            if (value == null || value.DataType == null)
            {
                if (member.Type.IsEnum)
                {
                    if (value == null)
                    {
                        value = new dataMember();
                    }
                    value.DataType = System.Enum.GetUnderlyingType(member.Type);
                }
                else
                {
                    dataMember sqlMember = fastCSharp.code.typeAttribute.GetAttribute <dataMember>(member.Type, false, false);
                    if (sqlMember != null && sqlMember.DataType != null)
                    {
                        if (value == null)
                        {
                            value = new dataMember();
                        }
                        value.DataType = sqlMember.DataType;
                        if (sqlMember.DataType.nullableType() != null)
                        {
                            value.IsNull = true;
                        }
                    }
                }
            }
            else if (member.Type.IsEnum)
            {
                Type enumType = System.Enum.GetUnderlyingType(member.Type);
                if (enumType != value.DataType)
                {
                    value.EnumType = enumType;
                }
            }
            if (value == null)
            {
                Type nullableType = member.Type.nullableType();
                if (nullableType == null)
                {
                    if (fastCSharp.code.typeAttribute.GetAttribute <sqlColumn>(member.Type, false, false) == null)
                    {
                        Type dataType = member.Type.formCSharpType().toCSharpType();
                        if (dataType != member.Type)
                        {
                            value          = new dataMember();
                            value.DataType = dataType;
                        }
                    }
                }
                else
                {
                    value        = new dataMember();
                    value.IsNull = true;
                    Type dataType = nullableType.formCSharpType().toCSharpType();
                    if (dataType != nullableType)
                    {
                        value.DataType = dataType.toNullableType();
                    }
                }
            }
            return(value ?? DefaultDataMember);
        }
예제 #3
0
        /// <summary>
        /// 格式化数据库成员信息
        /// </summary>
        /// <param name="value"></param>
        /// <param name="type"></param>
        /// <param name="isSqlColumn"></param>
        /// <returns></returns>
        internal static dataMember FormatSql(dataMember value, Type type, ref bool isSqlColumn)
        {
            if (type.IsEnum)
            {
                Type enumType = System.Enum.GetUnderlyingType(type);
                if (enumType == typeof(sbyte))
                {
                    enumType = typeof(byte);
                }
                else if (enumType == typeof(ushort))
                {
                    enumType = typeof(short);
                }
                else if (enumType == typeof(ulong))
                {
                    enumType = typeof(long);
                }
                if (value == null)
                {
                    return new dataMember {
                               DataType = enumType
                    }
                }
                ;
                if (value.DataType == null)
                {
                    value.DataType = enumType;
                }
                else if (enumType != value.DataType)
                {
                    value.EnumType = enumType;
                }
                return(value);
            }
            Type nullableType = null;

            if (type.IsGenericType)
            {
                Type genericType = type.GetGenericTypeDefinition();
                if (genericType == typeof(fastCSharp.sql.fileBlockMember <>))
                {
                    if (value == null)
                    {
                        return new dataMember {
                                   DataType = typeof(fastCSharp.io.fileBlockStream.index)
                        }
                    }
                    ;
                    value.DataType = typeof(fastCSharp.io.fileBlockStream.index);
                    return(value);
                }
                if (genericType == typeof(Nullable <>))
                {
                    nullableType = type.GetGenericArguments()[0];
                }
            }
            else if (fastCSharp.code.typeAttribute.GetAttribute <sqlColumn>(type, false, false) != null)
            {
                isSqlColumn = true;
                return(DefaultDataMember);
            }
            if (value == null || value.DataType == null)
            {
                dataMember sqlMember = fastCSharp.code.typeAttribute.GetAttribute <dataMember>(type, false, false);
                if (sqlMember != null && sqlMember.DataType != null)
                {
                    if (value == null)
                    {
                        value = new dataMember();
                    }
                    value.DataType = sqlMember.DataType;
                    if (sqlMember.DataType.IsValueType && sqlMember.DataType.IsGenericType && sqlMember.DataType.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        value.IsNull = true;
                    }
                }
            }
            if (value == null)
            {
                if (nullableType == null)
                {
                    Type dataType = type.formCSharpType().toCSharpType();
                    if (dataType != type)
                    {
                        value = new dataMember {
                            DataType = dataType
                        }
                    }
                    ;
                }
                else
                {
                    value = new dataMember {
                        IsNull = true
                    };
                    Type dataType = nullableType.formCSharpType().toCSharpType();
                    if (dataType != nullableType)
                    {
                        value.DataType = dataType.toNullableType();
                    }
                }
            }
            return(value ?? DefaultDataMember);
        }