Exemplo n.º 1
0
        /// <summary>
        /// 检索出Entity实例中有设置值的字段
        /// </summary>
        /// <typeparam name="T">实体类的类型</typeparam>
        /// <param name="entity">实体类的实例</param>
        /// <param name="effectiveEntityMemberNames">有效的Entity字段名称</param>
        /// <param name="entityPropertyInfos">实体类对应的属性</param>
        /// <returns>Entity实例中有设置值的字段</returns>
        public static List <string> GetNotNullFields <T>(T entity)
        {
            List <string>       entityFieldNames    = EntityMappingTool.GetEntityFieldNames((typeof(T)));
            List <PropertyInfo> entityPropertyInfos = EntityMappingTool.GetEntityPropertyInfos((typeof(T)));
            List <string>       notNullEntityFields = new List <string>(entityFieldNames.Count);

            for (int i = 0; i < entityFieldNames.Count; i++)
            {
                if (entityPropertyInfos[i].GetValue(entity, null) != null)
                {
                    notNullEntityFields.Add(entityFieldNames[i]);
                }
            }

            return(notNullEntityFields);
        }