Intellisense : What properties are required?

Yesterday I was talking to a Simon, another super smart dev on the EF team, and he raised a big concern, one that I am sure you can all relate too:

We've all seen something like this:

Intellisense

And thought: "What is the bare minimum I can do here to save a Whatever ?"

This "What properties are required ?" problem is particularly tricky when working with database Entities, because very often lots of the properties are nullable or server generated, but intellisense provides no clues.

Now my conversation with Simon reminded me of a couple of posts about intellisense planning I wrote on my old blog.

The basic idea was writing code with the aim of streamlining the programmers intellisense experience.

So yesterday Simon and I started having a think, and realised that perhaps Intellisense planning is the answer to this "What properties are required ?" problem too.

In fact all you need to do is this:

1) Create an interface for each entity called something like IRequiredForX, and then add only the properties you need to that interface:

i.e. something like this:

public interface IRequiredForPerson
{
     string Firstname {get;set;}
     string Surname {get;set;}
     Gender Gender {get;set;}
}

2) Make your class implement that interface, and (this is the key piece) add a property to return itself cast to the interface:

public class Person: IRequiredForPerson
{
    public IRequiredForPerson Required
    {
        get { return this; }
    }

Now the programmer can use intellisense to see only what is required:

BetterIntellisense

This is the sort of thing you could easily do in partial classes that extend the classes the Entity Framework creates for you. In fact, you could even write your own CodeGen to do this for you.

Never underestimate the power of intellisense, it can make all the difference.

Nifty huh?

Thanks for the idea Simon.

PS:
In case you're wondering, no I haven't forgotten about my statement of intent! I am working through a big list of possible 'real world' applications at the moment.

Expect some action on that front soon...