public static void Verify <TEntity>(DbContext context, IEnumerable <TEntity> entities) where TEntity : class { //判断是否开启字段值校验 if (!context.OpenPropertyDataValidate) { return; } if (entities == null || !entities.Any()) { return; } foreach (var propertyInfo in typeof(TEntity).GetProperties()) { foreach (var item in entities) { var value = propertyInfo.GetValue(item); //Require RequireAttribute.Verify(propertyInfo, value); //StringLength StringLengthAttribute.Verify(propertyInfo, value); //RangeLimit RangeLimitAttribute.Verify(propertyInfo, value); } } }
public void Verify <TEntity>(TEntity entity) where TEntity : class { if (entity == null) { return; } foreach (var propertyInfo in typeof(TEntity).GetProperties()) { var value = propertyInfo.GetValue(entity); //Require RequireAttribute.Verify(propertyInfo, value); //StringLength StringLengthAttribute.Verify(propertyInfo, value); //RangeLimit RangeLimitAttribute.Verify(propertyInfo, value); } }
public void Verify <TEntity>(IEnumerable <TEntity> entities) where TEntity : class { if (entities == null || !entities.Any()) { return; } foreach (var propertyInfo in typeof(TEntity).GetProperties()) { foreach (var item in entities) { var value = propertyInfo.GetValue(item); //Require RequireAttribute.Verify(propertyInfo, value); //StringLength StringLengthAttribute.Verify(propertyInfo, value); //RangeLimit RangeLimitAttribute.Verify(propertyInfo, value); } } }