예제 #1
0
        private void AddClassReleation(Type type)
        {
            Class2TableRel cdr = new Class2TableRel();

            object[] objs;
            if (type.IsDefined(typeof(DbTableAttribute), true))
            {
                objs = type.GetCustomAttributes(typeof(DbTableAttribute), true);
                cdr.ClassAttribute = ((DbTableAttribute)objs[0]);
                cdr.ClassType      = type;
            }
            else
            {
                throw new Exception(type.ToString() + "类未实现DbTableAttribute接口");
            }

            PropertyInfo[] propertyInfo = type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

            foreach (PropertyInfo p in propertyInfo)
            {
                if (p.IsDefined(typeof(DbFieldAttribute), true) && !p.IsDefined(typeof(DBFieldIgnoreAttribute), true))
                {
                    Property2FieldRel pfr = new Property2FieldRel();
                    object[]          o   = p.GetCustomAttributes(typeof(DbFieldAttribute), true);
                    pfr.PropertyInfo      = p;
                    pfr.PropertyAttribute = ((DbFieldAttribute)o[0]);

                    if (pfr.PropertyAttribute.DataType == DataType.Null)
                    {
                        pfr.PropertyAttribute.DataType = GetDatabaseType(p.PropertyType);
                    }

                    cdr.AddField(pfr);
                }
            }

            releation.Add(type, cdr);
        }
예제 #2
0
 public void AddField(Property2FieldRel pr)
 {
     ar.Add(pr);
 }