Skip to content

added handling for invalid values + unit tests to ensure that extraneous & invalid values are ignored#8

Merged
erinnmclaughlin merged 3 commits intomainfrom
unit-tests-for-extraneous-values
May 12, 2022
Merged

added handling for invalid values + unit tests to ensure that extraneous & invalid values are ignored#8
erinnmclaughlin merged 3 commits intomainfrom
unit-tests-for-extraneous-values

Conversation

@BenMakesGames
Copy link
Copy Markdown
Collaborator

No description provided.

@BenMakesGames BenMakesGames changed the title added unit tests to ensure that extraneous values are ignored added handling for invalid values + unit tests to ensure that extraneous & invalid values are ignored May 12, 2022
// Simple cases
if (!p.PropertyType.IsClass || p.PropertyType == typeof(string))
if (propertyType.IsGenericType)
propertyType = propertyType.GenericTypeArguments.First();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ 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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we do this earlier? like, before we do the check for nested classes and lists?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Collaborator Author

@BenMakesGames BenMakesGames May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ 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;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Rider 😸

@erinnmclaughlin erinnmclaughlin merged commit 3ea2536 into main May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants