Skip to content

Commit

Permalink
SetPropertyValues better handles Dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
yohsii committed Jan 5, 2020
1 parent 02ef616 commit 94b1090
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions core/Helpers/ObjectDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ public static void SetPropertyValues(object obj,bool onlyPopulateListEditorLists

var subObject = Activator.CreateInstance(propType);

if (propType.IsGenericType /*&&
if (propType.IsGenericType && propType.GetGenericArguments().Length == 1
/*&&
propType.GetGenericTypeDefinition()
== typeof(IList<>)*/)
{
Expand All @@ -594,11 +595,11 @@ public static void SetPropertyValues(object obj,bool onlyPopulateListEditorLists
{
listItem = (Single?)0f;
}
else if (itemType==typeof(Char?))
else if (itemType == typeof(Char?))
{
listItem = (Char?)' ';
}
else if (itemType==typeof(Decimal?))
else if (itemType == typeof(Decimal?))
{
listItem = (Decimal?)0m;
}
Expand All @@ -625,13 +626,18 @@ public static void SetPropertyValues(object obj,bool onlyPopulateListEditorLists
else
listItem = Activator.CreateInstance(itemType);
subObject.GetType().GetMethod("Add").Invoke(subObject, new[] { listItem });
if(depth<SetPropertyValuesMaxDepth && listItem!=null)
SetPropertyValues(listItem,onlyPopulateListEditorLists:onlyPopulateListEditorLists,depth:depth+1,setNullableFields:setNullableFields);
if (depth < SetPropertyValuesMaxDepth && listItem != null)
SetPropertyValues(listItem, onlyPopulateListEditorLists: onlyPopulateListEditorLists, depth: depth + 1, setNullableFields: setNullableFields);
}
property.SetValue(obj, subObject, null);
}


else if (propType.GetGenericArguments().Length > 1) {
if (propType.GetGenericArguments().Length == 2) {
//likely a dictionary
Type keyType = propType.GetGenericArguments()[0];
//TODO, handle dictionaries
}
}
}
else
if (property.PropertyType.IsClass && property.PropertyType != typeof(string))
Expand Down

0 comments on commit 94b1090

Please sign in to comment.