Eric's Blog

Day to day experience in .NET
Welcome to Blogs @ IRM Sign in | Join | Help
 Search

Disclaimer

The content of this site is my own personal opinion and does not in any way represent my employer, it's subsideries or affiliates. These postings are provided "AS IS" with no warranties, and confer no rights.

This Blog

An Missing Interface

.NET 2.0 is missing an INullable interface! It's great that Nullable<T> was added to version 2 of .NET Framework, but why doesn't it implement an interface, where the interface has the HasValue property defined?
My problem is that I wanted to write some library code, where I wanted to be able to handle Nullable types. More precisely I wanted to know if the Nullable type had an value or not. In this situation I'm not interested in what type (T) it actually has, only if it has any value or not. Since I don't know T, I'm not able to make any type of cast and therefore had to use reflection to solve my problem. If Nullable<T> would have implemented an interface that exposed HasValue, this would not have been necessary.
I think that the lesson to be learned is that when you design your generic types, you should consider doing an interface that exposes methods and properties that are not in need of the specific type (T). This would make your code much easier to use in some situations and wouldn't bring much extra work to the table.
Published den 22 mars 2007 18:41 by ericqu
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server, by Telligent Systems