Example #1
0
        /// <summary>
        /// 获取属性-所有Field(带排序)
        /// </summary>
        /// <param name="objEntity"></param>
        /// <returns></returns>
        public static List <EntityAttribute> GetFieldAttribute(BaseDataContract objEntity)
        {
            try
            {
                List <EntityAttribute> lstAttri       = new List <EntityAttribute>();
                PropertyInfo[]         objPropertyArr = objEntity.GetType().GetProperties();

                EntityAttribute attri = null;
                foreach (var item in objPropertyArr)
                {
                    attri = EntityTools.GetAttribute(item);
                    if (attri != null)
                    {
                        lstAttri.Add(attri);
                    }
                }
                if (lstAttri != null && lstAttri.Count > 0)
                {
                    lstAttri.Sort();
                }
                return(lstAttri);
            }
            catch
            {
                return(null);
            }
        }
Example #2
0
 /// <summary>
 /// 获取属性-Table
 /// </summary>
 /// <param name="objEntity"></param>
 /// <returns></returns>
 internal static EntityAttribute GetTableAttribute(BaseDataContract objEntity)
 {
     try
     {
         return(GetAttribute(objEntity.GetType()));
     }
     catch
     {
         return(null);
     }
 }
Example #3
0
 /// <summary>
 /// 获取属性-Field
 /// </summary>
 /// <param name="objEntity"></param>
 /// <param name="fieldName"></param>
 /// <returns></returns>
 public static EntityAttribute GetFieldAttribute(BaseDataContract objEntity, string fieldName)
 {
     try
     {
         PropertyInfo[] objPropertyArr = objEntity.GetType().GetProperties();
         return((EntityAttribute)(objPropertyArr.FirstOrDefault(t => t.Name.ToLower() == fieldName.ToLower())).GetCustomAttributes(typeof(EntityAttribute), false)[0]);
     }
     catch
     {
         return(null);
     }
 }
Example #4
0
 /// <summary>
 /// 获取属性-Field
 /// </summary>
 /// <param name="objEntity"></param>
 /// <param name="fieldName"></param>
 /// <returns></returns>
 internal static PropertyInfo GetFieldProperty(BaseDataContract objEntity, string fieldName)
 {
     try
     {
         PropertyInfo[] objPropertyArr = objEntity.GetType().GetProperties();
         return(objPropertyArr.FirstOrDefault(t => t.Name.ToLower() == fieldName.ToLower()));
     }
     catch
     {
         return(null);
     }
 }
Example #5
0
        /// <summary>
        /// 获取属性-Field.Value
        /// </summary>
        /// <param name="objEntity"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static object GetFieldValue(BaseDataContract objEntity, string fieldName)
        {
            PropertyInfo property = GetFieldProperty(objEntity, fieldName);

            if (property != null)
            {
                return(property.GetValue(objEntity, null));
            }
            else
            {
                return(null);
            }
        }
Example #6
0
        /// <summary>
        /// 获取实体字段类型
        /// </summary>
        /// <param name="objEntity"></param>
        /// <returns></returns>
        public static EntityFieldAttribute[] GetEntityFieldAttri(BaseDataContract objEntity)
        {
            EntityFieldAttribute        fieldAttri    = null;
            List <EntityFieldAttribute> lstFieldAttri = new List <EntityFieldAttribute>();

            PropertyInfo[] propertyInfo = objEntity.GetType().GetProperties();
            foreach (PropertyInfo item in propertyInfo)
            {
                fieldAttri           = new EntityFieldAttribute();
                fieldAttri.FieldName = item.Name;
                fieldAttri.FieldType = Nullable.GetUnderlyingType(item.PropertyType) ?? item.PropertyType;
                lstFieldAttri.Add(fieldAttri);
            }
            return(lstFieldAttri.ToArray());
        }
Example #7
0
 /// <summary>
 /// 获取属性-Field
 /// </summary>
 /// <param name="objEntity"></param>
 /// <param name="obj"></param>
 /// <returns></returns>
 internal static PropertyInfo GetFieldProperty(BaseDataContract objEntity, EntityAttribute obj)
 {
     try
     {
         PropertyInfo[]  objPropertyArr = objEntity.GetType().GetProperties();
         EntityAttribute attri          = null;
         foreach (var item in objPropertyArr)
         {
             attri = EntityTools.GetAttribute(item);
             if (attri != null && attri.FieldName.ToLower() == obj.FieldName.ToLower())
             {
                 return(item);
             }
         }
         return(null);
     }
     catch
     {
         return(null);
     }
 }
Example #8
0
 /// <summary>
 /// 获取表名
 /// </summary>
 /// <param name="objEntity"></param>
 /// <returns></returns>
 public static string GetTableName(BaseDataContract objEntity)
 {
     return(EntityTools.GetTableAttribute(objEntity).TableName);
 }
Example #9
0
 /// <summary>
 /// 获取属性-Seq.Field(带排序)
 /// </summary>
 /// <param name="objEntity"></param>
 /// <param name="flag"></param>
 /// <returns></returns>
 internal static List <EntityAttribute> GetFieldAttributeSeq(BaseDataContract objEntity)
 {
     return(GetFieldAttribute(objEntity, 2));
 }
Example #10
0
 /// <summary>
 /// 获取属性-PK.Field(带排序)
 /// </summary>
 /// <param name="objEntity"></param>
 /// <returns></returns>
 public static List <EntityAttribute> GetFieldAttributePk(BaseDataContract objEntity)
 {
     return(GetFieldAttribute(objEntity, 1));
 }