I've seen some examples where they transformed a call like
void Add(IDrawing item);
into
void Add<TDrawing>(TDrawing item) where TDrawing : IDrawing;
Beside tricking the intellisense into displaying the name of your class instead of the interface name when calling the function, because of inferred type usage in C#4, are there any other advantage to using the second approach?
To answer Jon Skeet, the code our programmer used is:
public ObservableCollection<IDrawing> Items { get; private set; }
public void Add<TDrawing>(TDrawing item) where TDrawing : IDrawing
{
this.Items.Add(item);
}
I don't see any advantage here for using a generic instead of just using a parameter of the IDrawing
type. I presume there must be some case where its very appropriate. I was curious to see if I was missing something.