Ejemplo n.º 1
0
        /// <summary>
        /// Sets the select ORM mapper.
        /// </summary>
        /// <returns>The select ORM mapper.</returns>
        /// <param name="mapper">Mapper.</param>
        /// <param name="flag">Flag.</param>
        /// <param name="index">Index.</param>
        public static SelectORMMaker SetSelectORMMaker(SelectORMMaker mapper, BindingFlags flag = BindingFlags.NonPublic)
        {
            if (mapper.Type == null)
            {
                return(mapper);
            }

            Type             copyType   = mapper.Type;
            List <FieldInfo> fieldInfos = GetFields(mapper.Type, flag);

            foreach (FieldInfo field in fieldInfos)
            {
                // table
                mapper.SetType(copyType);

                // FK
                ColumnAttribute column = field.GetAttributeValue <ColumnAttribute> ();
                if (column != null && column.CheckConstraints(DataConstraints.FK))
                {
                    if (column.Key != null && column.Value != "")
                    {
                        mapper.SetJoin(column.Key, column.Value, field.Name);
                    }
                    else
                    {
                        HDebug.LogWarning(field.Name + " the column attribute is set problem");
                    }
                }

                // select
                if (Util.IsValueType(field.FieldType))
                {
                    mapper.SetSelect(field.Name);
                }
                else
                {
                    if (mapper.SetType(field.FieldType, copyType) == "")
                    {
                        HDebug.LogWarning(field.FieldType + " the table is not set.");
                        mapper.SetType(copyType);
                    }
                    else
                    {
                        JoinAttribute join = field.GetAttributeValue <JoinAttribute> ();
                        if (join == null)
                        {
                            mapper.SetJoinType();
                        }
                        else
                        {
                            mapper.SetJoinType(join.Type);
                        }

                        SetSelectORMMaker(mapper, flag);
                    }
                }
            }

            return(mapper);
        }