Skip to content

Commit

Permalink
修复 Convert.ChangeType 使用空值引起的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Roc committed Jun 28, 2019
1 parent 486d0ab commit f235fc5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public class QPayListPropertyParser
foreach (var field in properties)
{
var name = $"{GetKeyName(field)}_{i}";
field.SetValue(item, Convert.ChangeType(dictionary.GetValue(name), field.PropertyType));
var value = dictionary.GetValue(name);
if (!string.IsNullOrEmpty(value))
{
field.SetValue(item, Convert.ChangeType(value, field.PropertyType));
}
}
list.Add(item);
}
Expand Down Expand Up @@ -54,7 +58,11 @@ public class QPayListPropertyParser
foreach (var subfield in subProperties)
{
var name = $"{GetKeyName(subfield)}_{i}_{j}";
subfield.SetValue(item, Convert.ChangeType(dictionary.GetValue(name), subfield.PropertyType));
var value = dictionary.GetValue(name);
if (!string.IsNullOrEmpty(value))
{
subfield.SetValue(item, Convert.ChangeType(value, subfield.PropertyType));
}
}
sublist.Add(subItem);
}
Expand All @@ -63,7 +71,11 @@ public class QPayListPropertyParser
else
{
var name = $"{GetKeyName(field)}_{i}";
field.SetValue(item, Convert.ChangeType(dictionary.GetValue(name), field.PropertyType));
var value = dictionary.GetValue(name);
if (!string.IsNullOrEmpty(value))
{
field.SetValue(item, Convert.ChangeType(value, field.PropertyType));
}
}
}
list.Add(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public class WeChatPayListPropertyParser
foreach (var field in properties)
{
var name = $"{GetKeyName(field)}_{i}";
field.SetValue(item, Convert.ChangeType(dictionary.GetValue(name), field.PropertyType));
var value = dictionary.GetValue(name);
if (!string.IsNullOrEmpty(value))
{
field.SetValue(item, Convert.ChangeType(value, field.PropertyType));
}
}
list.Add(item);
}
Expand Down Expand Up @@ -54,7 +58,11 @@ public class WeChatPayListPropertyParser
foreach (var subfield in subProperties)
{
var name = $"{GetKeyName(subfield)}_{i}_{j}";
subfield.SetValue(item, Convert.ChangeType(dictionary.GetValue(name), subfield.PropertyType));
var value = dictionary.GetValue(name);
if (!string.IsNullOrEmpty(value))
{
subfield.SetValue(item, Convert.ChangeType(value, subfield.PropertyType));
}
}
sublist.Add(subItem);
}
Expand All @@ -63,7 +71,11 @@ public class WeChatPayListPropertyParser
else
{
var name = $"{GetKeyName(field)}_{i}";
field.SetValue(item, Convert.ChangeType(dictionary.GetValue(name), field.PropertyType));
var value = dictionary.GetValue(name);
if (!string.IsNullOrEmpty(value))
{
field.SetValue(item, Convert.ChangeType(value, field.PropertyType));
}
}
}
list.Add(item);
Expand Down

0 comments on commit f235fc5

Please sign in to comment.