Condividi tramite


Nullable Types

I'm pretty excited about Nullable Types in Whidbey. The primary reason I care about this is that in my PhotoLibrary (library that exposes EXIF properties of a picture) has lot of value types like int. One neat thing about the class is that using something like a PropertyGrid you can just point it at the Photo object and it will automatically reflect all the meta data and display it (with very little work). Well if a Picture doesn't contain certain properties, the reference types simply don't appear because they are null. Well, unfortunately all the value types appear in the property grid because they are set to 0. I never found an easy to way filter these out, and there are quite a few EXIF properties out there, which leads to a lot of unnecessary data in the property grid.

Anyway, this should fix that :-)

Comments

  • Anonymous
    January 07, 2005
    These Nullable Types are a really bad design decision in my eyes. This drives the language into a "C++-direction" meaning that it gets more bloated and more complicated.
  • Anonymous
    January 08, 2005
    As this is purely usable for value types, why not create a library facility (instead of a language facility) to wrap a value type in a reference type? Wouldn't a simple generic class work in all cases? Something like this?

    public final class Nullable<T>
    {
    private T t;

    public Nullable(T t)
    {
    this.t = t;
    }

    public static implicit operator T(Nullable n)
    {
    return n.t;
    }
    }