csharp 自定义JsonServialize验证
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 自定义JsonServialize验证相关的知识,希望对你有一定的参考价值。
private List<KeyValuePair<string, string>> GetInvalidAccountProps(List<AccountErcDto> accounts)
{
var props = typeof(AccountErcDto).GetProperties();
var requireProps = new List<string> { "UkOgrn", "PremiseNum", "Entrance", "TotalArea", "HouseGuid", "IsRenter", "IsLiving", "Number" };
var invalidCells = new List<KeyValuePair<string, string>>();
foreach (var account in accounts)
{
foreach (var prop in props)
{
var val = prop.GetValue(account, null);
bool isNull = false;
var type = prop.GetValue(account, null).GetType().ToString();
switch (type)
{
case "System.String":
isNull = String.IsNullOrWhiteSpace(val.ToString());
break;
case "System.Decimal":
isNull = default(decimal) == Convert.ToDecimal(val);
break;
case "System.Int32":
isNull = default(int) == Convert.ToInt32(val);
break;
case "System.Boolean":
isNull = String.IsNullOrWhiteSpace(val.ToString());
break;
}
if (isNull && requireProps.Contains(prop.Name))
{
invalidCells.Add(new KeyValuePair<string, string>(account.Number, prop.GetCustomAttribute<DescriptionAttribute>()?.Description));
}
}
}
return invalidCells;
}
以上是关于csharp 自定义JsonServialize验证的主要内容,如果未能解决你的问题,请参考以下文章
csharp 带有自定义分类和消息的SharePoint 2010自定义日志条目
csharp JSON自定义字段合同解析器
csharp 自定义对话窗口
csharp MaxWords自定义验证注释属性
csharp 自定义路线
csharp 自定义Sitefinity小部件