-
Notifications
You must be signed in to change notification settings - Fork 401
Feature/nullable constructors #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/nullable constructors #141
Conversation
@anjdreas Did you miss this one when you merged #142 or do you have any questions/objections? |
Sorry for the delay, it's good you follow up. As you can see I had some immediate thoughts and that's why it got a bit postponed. Let me know what you think. |
…lues from nullable doubles
I've now changed to calling the non-nullable functions when the nullable double has a value (decreased the size with 4KB, original size before the nullable constructors was 215KB, new size is 252 KB). If you know the details about all units it makes sense to test only the ones with different implementation details (I didn't even know that Following that argument through I should have used a for-each loop for all different units in the different units of measure. But in some way I agree with you, there are many tests already and it feels like they're not really testing anything. My guess is that the only thing these tests really tests is overload resolution problems. These would only occur if custom constructors were added, that is also an argument for more tests. As you can see I'm torn. I'll think of it during the day and get back to you. |
…ure/nullable-constructors
I've contemplated the very same thing. I agree with your point about tests protecting future refactors, where some units are start differing from others. These are my initial thoughts:
What do you think? |
|
Moved tests to the file NullableConstructors.cs. Currently testing Length and Information. Not sure if the file should be in "CustomCode" or in the project root though. What do you think? |
In the root I think, since it is not testing an implementation in the CustomCode folder. |
Thanks. Moved "NullableConstructors.cs". Should be ready to merge now. |
MethodInfo fromMethod = reflectedUnitType.GetMethod("From"); | ||
MethodInfo fromMethod = (from m in reflectedUnitType.GetMethods() | ||
where m.Name.Equals("From", StringComparison.InvariantCulture) && | ||
!m.ReturnType.IsGenericType // we want the non nullable type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed this. It probably works already, but I found a post on how to properly test for nullable.
http://stackoverflow.com/a/374663/134761
Do you think we should use that method instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests captured this, hence the change (I would never have discovered it without the tests). Since there is a test that checks that this work I would leave it as is. We could add m.ReturnType.IsValueType && Nullable.GetUnderlyingType(m.ReturnType) == null
but what's there right now works and it seems unlikely that more functions named From
are added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fair enough. We will leave it as-is.
Add nullable constructor methods
Nuget 3.28 is out. |
Added static "constructors" for nullable doubles as a convenience. When calling the
.FromUnitName()
or.From()
with a nullable double you now get a nullable unit of measure back.