Conversation
|
I spent some time starting this. I have fixed most issues (errors look worse than they are because the types can't be generated until the build is fixed) but there is some internal stuff that I'm unsure of. It seems that there are a lot of places where we are not handling potential nulls correctly. @Turnerj Would you like to cast your eye over the last 10% of errors? Then I'll see if I can fix anything that's left. |
|
Yep, no problem! |
| } | ||
|
|
||
| try | ||
| if (Enum.TryParse(targetType, enumString, out result)) |
There was a problem hiding this comment.
Enum.TryParse instead of try/catch. This could also be in another PR.
There was a problem hiding this comment.
Don't know why we didn't do this sooner!
There was a problem hiding this comment.
Exactly! Performance win too!
There was a problem hiding this comment.
I think I found out why - that method doesn't exist in .NET Standard 2.0 😣
There was a problem hiding this comment.
Perhaps we can write our own TryParse that supports old platforms? That would move the ugly #if out of this code and turn this into a one liner.
There was a problem hiding this comment.
Done! Created an EnumHelper static class with a TryParse method that copies the signature for Enum.TryParse.
|
Nullable references support for the tool is done. Will look into the other bits left for the various |
Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaEnumeration.cs
Outdated
Show resolved
Hide resolved
Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaProperty.cs
Outdated
Show resolved
Hide resolved
| #if NETSTANDARD2_0 || NET472 || NET461 | ||
| try | ||
| { | ||
| result = Enum.Parse(targetType, enumString); | ||
| success = true; | ||
| } | ||
| catch (Exception) | ||
| #else | ||
| if (Enum.TryParse(targetType, enumString, out result)) |
There was a problem hiding this comment.
This seemed like an OK compromise. Not a huge fan of using 3 targets like I am here though.
It did make me wonder, why do we target .NET 4.7.2 and .NET 4.6.1 directly when we also target .NET Standard 2.0?
There was a problem hiding this comment.
I repeat this type of check here as well with my switched up way to generate a ToString for PropertyValueSpecification: 85dde5a#diff-4170f976c7ab6112252917fe8fa2c6a2ce7bed515547e0e42e11ea4d67402f9dR47-R51
There was a problem hiding this comment.
Unfortunately there are severe bugs in .NET 4.7.2 and .NET 4.6.1 full framework when targetting netstandard2.0. I haven't used full framework for years but have had issues raised to add full framework back in (it's surprising how many people still use it).
|
What are your thoughts about disabling nullable reference types for our tests? Our tests are designed to check very specific conditions anyway and will fail on any exception. We might be just adding all the additional markup for it just for it to be mostly irrelevant. |
RehanSaeed
left a comment
There was a problem hiding this comment.
The tests I've enabled nullable for have mostly involved liberal use of ! and ? with the occasional switch to immutable types. So nothing too onerous. We don't have many changes to tests currently but not sure if that'll change once everything is converted. Agree that it did feel mostly irrelevant, although I did manage to make the odd improvement.
Overall, I've been surprised at how little code has had to change to my other repos (this one seems the most complex) and nullable seems to have only made a marginal improvement.
| } | ||
|
|
||
| try | ||
| if (Enum.TryParse(targetType, enumString, out result)) |
There was a problem hiding this comment.
Perhaps we can write our own TryParse that supports old platforms? That would move the ugly #if out of this code and turn this into a one liner.
| var book = JsonConvert.DeserializeObject<Book>(this.json, TestDefaults.DefaultJsonSerializerSettings); | ||
| var book = JsonConvert.DeserializeObject<Book>(this.json, TestDefaults.DefaultJsonSerializerSettings)!; | ||
|
|
||
| Assert.True(book.Author.HasValue); |
There was a problem hiding this comment.
Apparently Assert.NotNull supports nullable reference types, so if you assert that and use it's return value, you can avoid the exclamation here.
| { | ||
| Assert.Equal(a.GetHashCode(), b?.GetHashCode()); | ||
| Assert.NotNull(a); | ||
| Assert.Equal(a!.GetHashCode(), b?.GetHashCode()); |
There was a problem hiding this comment.
Same here about Assert.NotNull
|
Build is green! |
|
LGTM, are we ready to merge? |
|
Yeah, I'm happy with it! |


Fixes #127