added handling for invalid values + unit tests to ensure that extraneous & invalid values are ignored#8
Conversation
| // Simple cases | ||
| if (!p.PropertyType.IsClass || p.PropertyType == typeof(string)) | ||
| if (propertyType.IsGenericType) | ||
| propertyType = propertyType.GenericTypeArguments.First(); |
There was a problem hiding this comment.
^ for simple cases - plain properties - if the property is GENERIC, we have to do some extra work to pull out the generic type.
for this reason, I also expanded unit tests to explicitly test classes with generic properties AND non-generic classes
There was a problem hiding this comment.
should we do this earlier? like, before we do the check for nested classes and lists?
There was a problem hiding this comment.
nope! I tried that, and it didn't work, because, for example, List<string> is also IsGenericType; if we drill into string there, we miss the class
| { | ||
| dict.Add(p.Name, value); | ||
| if(Enum.TryParse(propertyType, str, out var value)) | ||
| dict.Add(p.Name, value); |
There was a problem hiding this comment.
^ previously, an unsuccessful enum parse would cause the code to continue to the default "just deserialize the thing" logic (below), which would fail, because the enum could not be successfully parsed :P
changed it so that an unsuccessful enum parse is skipped entirely.
|
|
||
| foreach (var p in type.GetProperties()) | ||
| { | ||
| var propertyType = p.PropertyType; |
No description provided.