/// <summary> /// 检测是否是主键 /// </summary> /// <param name="property"></param> /// <returns></returns> private bool CheckIsKey(PropertyDes property) { if (property.CusAttribute is KeyAttribute || property.Field == "Id") { return(true); } return(false); }
/// <summary> /// 获取属性信息 /// </summary> /// <param name="type"></param> /// <param name="model"></param> /// <returns></returns> internal void GetPropertyInfo(Type type, EntityInfo model) { #region 属性描述 foreach (var propertyInfo in type.GetProperties()) { var pty = new PropertyDes { Field = propertyInfo.Name, Column = propertyInfo.Name, PropertyType = propertyInfo.PropertyType, PropertyInfo = propertyInfo }; var attributesList = propertyInfo.GetCustomAttributes(typeof(BaseAttribute), true); pty.CusAttribute = attributesList.Select(item => item as BaseAttribute).ToList(); var isIgnore = false; var customAttribute = propertyInfo.GetCustomAttributes(typeof(ColumnAttribute), true).FirstOrDefault(); if (customAttribute is ColumnAttribute) { var columnAttribute = (customAttribute as ColumnAttribute) ?? new ColumnAttribute(); if (!string.IsNullOrEmpty(columnAttribute.Name)) { pty.Column = columnAttribute.Name; } } foreach (var attributes in attributesList) { if (attributes is IgnoreAttribute) { isIgnore = true; break; } if (attributes is KeyAttribute) { //pty.CusAttribute = attributes as KeyAttribute; break; } } if (!isIgnore) { model.Properties.Add(pty); } } #endregion }