自定义成员信息
示例#1
0
        /// <summary>
        /// 获取自增字段成员
        /// </summary>
        /// <param name="type"></param>
        /// <param name="model"></param>
        /// <returns>自增字段成员</returns>
        public static memberInfo GetIdentity <modeType>(Type type, modeType model) where modeType : dataModel
        {
            fieldIndex[] fields   = (fieldIndex[])typeof(fastCSharp.code.memberIndexGroup <>).MakeGenericType(type).GetMethod("GetFields", BindingFlags.Static | BindingFlags.Public).Invoke(null, new object[] { model.MemberFilter });
            memberInfo   identity = null;
            int          isCase   = 0;

            foreach (fieldIndex field in fields)
            {
                type = field.Member.FieldType;
                if (!type.IsPointer && (!type.IsArray || type.GetArrayRank() == 1) && !field.IsIgnore)
                {
                    dataMember attribute = field.GetSetupAttribute <dataMember>(true, true);
                    if (attribute != null && attribute.IsIdentity)
                    {
                        return(new memberInfo(field.Member, 0));
                    }
                    if (isCase == 0 && field.Member.Name == fastCSharp.config.sql.Default.DefaultIdentityName)
                    {
                        identity = new memberInfo(field.Member, 0);
                        isCase   = 1;
                    }
                    else if (identity == null && field.Member.Name.ToLower() == fastCSharp.config.sql.Default.DefaultIdentityName)
                    {
                        identity = new memberInfo(field.Member, 0);
                    }
                }
            }
            return(identity);
        }
示例#2
0
        /// <summary>
        /// 获取字段成员集合
        /// </summary>
        /// <param name="type"></param>
        /// <param name="attribute"></param>
        /// <param name="memberCountVerify"></param>
        /// <param name="fixedSize"></param>
        /// <param name="nullMapSize"></param>
        /// <returns>字段成员集合</returns>
        public static subArray <memberInfo> GetFields(Type type, dataSerialize attribute, out int memberCountVerify, out int fixedSize, out int nullMapSize)
        {
            fieldIndex[]          fieldIndexs = (fieldIndex[])typeof(fastCSharp.code.memberIndexGroup <>).MakeGenericType(type).GetMethod("GetFields", BindingFlags.Static | BindingFlags.Public).Invoke(null, new object[] { attribute.MemberFilter });
            subArray <memberInfo> fields      = new subArray <memberInfo>(fieldIndexs.Length);
            int nullMapIndex = 0;

            fixedSize = nullMapSize = 0;
            foreach (fieldIndex field in fieldIndexs)
            {
                type = field.Member.FieldType;
                if (!type.IsPointer && (!type.IsArray || type.GetArrayRank() == 1) && !field.IsIgnore)
                {
                    fastCSharp.emit.dataSerialize.member memberAttribute = field.GetAttribute <fastCSharp.emit.dataSerialize.member>(true, true);
                    if (memberAttribute == null || memberAttribute.IsSetup)
                    {
                        memberInfo value = memberInfo.GetSerialize(field);
                        if (type != typeof(bool))
                        {
                            fixedSize += value.SerializeFixedSize;
                        }
                        nullMapSize += value.NullMapSize;
                        if (value.NullMapSize == 2)
                        {
                            value.SerializeNullMapIndex = nullMapIndex;
                            nullMapIndex += 2;
                            --fixedSize;
                        }
                        fields.Add(value);
                    }
                }
            }
            memberCountVerify = fields.length + 0x40000000;
            fixedSize         = (fixedSize + 3) & (int.MaxValue - 3);
            nullMapSize       = ((nullMapSize + 31) >> 5) << 2;
            fields.Sort(memberInfo.SerializeFixedSizeSort);
            foreach (memberInfo value in fields)
            {
                if (value.NullMapSize == 1)
                {
                    value.SerializeNullMapIndex = nullMapIndex++;
                }
            }
            return(fields);
        }