Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

IsInstanceOf<T>() is not consistent accross types #68

Closed
dupdob opened this issue Jul 10, 2013 · 6 comments
Closed

IsInstanceOf<T>() is not consistent accross types #68

dupdob opened this issue Jul 10, 2013 · 6 comments
Milestone

Comments

@dupdob
Copy link
Collaborator

dupdob commented Jul 10, 2013

While working on #66 I realized that IsInstanceOf<Person>() fails for null values (NullRefExceprion), but it works there: Check.That( (int?) null).IsInstanceOf<int?>().

It raises multiple questions:
1. is this ok?
I do not think so.

2. What should be the behaviour?
Based on the check name, I propose that null always fail

3. What should we do for Nullables?
Reminder: Nullable types cannot be identified as such at compilation time. At run time, they are either null or a value of the underlying type. As such, GetType() behaves as expected, either throwing a NullRefExc or the appropriate struct type. Furthermore Nullable cannot be inherited from.

It implies that the nullableness can only be checked at compilation time, Therefore IsInstanceOf<int ?> does not bring any value. By the same token, Check.That((int?) 4).IsInstanceOf<T>() can only succeed for T= int?

@dupdob
Copy link
Collaborator Author

dupdob commented Jul 10, 2013

Now I understand where it comes from. IsInstanceOf has no interest for actual value type.
But it does for boxed type

@dupdob
Copy link
Collaborator Author

dupdob commented Jul 12, 2013

Ultimately, I re implemented IsInstanceOf with the same contract, but it is now made available to all types

@tpierrain
Copy link
Owner

Since:

  • You finally find a way to check whether a Type is nullable or not (i.e. the IsNullable(this Type...) of the ExtensionsCommonHelpers)
  • It was very odd to have messages such as: The checked value is not of the given type... The checked value [null] of type [int?] The given type: [int?]

I finally changes the implementation so that a nullable type without a value may succeed if it is the same nullable type.

@dupdob
Copy link
Collaborator Author

dupdob commented Jul 15, 2013

Ok, as I usually say for such edge cases: let's see the feedback we get, if
any :-)

@tpierrain
Copy link
Owner

tpierrain commented Jul 15, 2013

I think that there is indeed no real use case for such edge case checks (on
the type of a nullable instance without a value), but the previous error
messages was so screaming at us: "stricto sensu, you can´t say that!" ;-)
that I finally could´t let it be...

T

@dupdob
Copy link
Collaborator Author

dupdob commented Jul 15, 2013

I fully agree with your statement, but I lack the energy for longer
explaination today ;-)
I was thinking: one extra reason to get rid of those (checks)
Thanks for checking message quality

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants