修改json 序列化绑定值
continuous-integration/drone/push Build is passing Details

Test_IRC_Net8
hang 2026-01-19 15:00:35 +08:00
parent 473d10533a
commit 296ecfa9d2
1 changed files with 15 additions and 2 deletions

View File

@ -101,12 +101,25 @@ namespace IRaCIS.Core.API
public void SetValue(object target, object value) public void SetValue(object target, object value)
{ {
_memberInfo.SetValue(target, value);
//// 会影响 string? 传递null 变为"" //// 会影响 string? 传递null 变为""
//if (_memberInfo.PropertyType == typeof(string)) var isNullable1 = _memberInfo.CustomAttributes.Any(a => a.AttributeType.Name == "NullableAttribute");
if (_memberInfo.PropertyType == typeof(string) && isNullable1 == false)
{
//如果不处理 前段传递null string不会接收说前段没传递会验证报错
_memberInfo.SetValue(target, value == null ? string.Empty : value);
}
else
{
_memberInfo.SetValue(target, value);
}
//if ()
//{ //{
// //去掉前后空格 // //去掉前后空格
// _memberInfo.SetValue(target, value == null ? string.Empty : value.ToString() == string.Empty ? value : value/*.ToString().Trim()*/); // _memberInfo.SetValue(target, value == null ? string.Empty : value.ToString() == string.Empty ? value : value/*.ToString().Trim()*/);