Diego Gonzalez

.NET, movies & //TODO:

October 2003 - Posts

Whidbey's Nullable<T> template

One of the new templates added in Whidbey's BCL is Nullable, which allows defining Nullable providing "nullness" on value types. The usage is very simple:


Nullable oi = null;
Console.WriteLine( oi.HasValue ); // false
Console.WriteLine( oi == null ); // true
oi = 3;
Console.WriteLine( oi.HasValue ); // true
Console.WriteLine( oi == null ); // false

The instance can be null because it's a reference type and the assignment can be done because operators are also specialized for type T.

I don't want to talk about the difference between ValueTypes and ReferenceTypes, or if the performance of the Nullable instances can be compared with the ValueTypes usage. But i was wondering about its usage in applications and probably their usage could be a bit complicated.

Any method that wanted to receive any value will receive an object:


void MyMethod( object t ){}

In the method body any one will query if the value is a ValueType or a ReferenceType. Now we have to ask for the instance to see if it's an Nullable<> instance. But what is the template implementation that will be used to query using the "is" keyword, there's no way to use the template as an abstract base class, so we can't know what is the type without using Reflection.

I have some solution for this. If the Nullable is declared using an interface defining the property HasValue, we can solve the problem because any template implementation will also implement the interface and "is" can be used to query the type of the reference.

public interface INullable
{
bool HasValue{ get; set; }
}
public class Nullable : IINullable
{
   // implementation
}

Posted: Oct 18 2003, 08:36 PM by DiegoGonzalez | with 1 comment(s)
Filed under:
Lars Von Trier's Dogville
He did it again!, yesterday i went to the movies to see Dogville, and i'm amazed. Lars von Tirer is an incredible director, he really knows how to tell a story and how to surprise again and again with each movie he creates.
Dogville is a story about a small american town, the houses are painted in the floor and there are no walls in an incredible scenario, with no sky, no sun, in a black or white environment with only nature noises (birds, dogs, rain).
The people in that town receives a strange visitor (Nicole Kidman) and the movie shows how the town inhabitants react to the visit, how the complete town starts "leaving" with her, in a story full of metaphors and hidden messages.
Posted: Oct 03 2003, 12:51 PM by DiegoGonzalez | with 7 comment(s)
Filed under:
MVP Again
I'm very glad to announce my MVP award was renewed for the next year, so i'll be an MVP for .Net technologies. This year and the next one i'll be traveling by the region in conferences and courses so i hope i can meet you.
Thanks MS folks and Latam Comunity.
More Posts