View Single Post
  #1 (permalink)  
Old August 19th, 2007, 04:09 AM
Ixtlia Ixtlia is offline
Registered User
Join Date: Aug 2007
Location: , , Russia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Guidelines Item 3: Replace System.Type with Type

Hello everyone. Can anyone point me what is a big deal in 3rd guidelines item? Tod advices to use:
public T FindPerson<T>(T personType, int id) {}
instead of
public object FindPerson(Type personType, int id) {}
The thing I can't understand is why is the first piece of code is better. Let's imagine we have a class named PersonFinder and it has the FindPerson method. So what would be the usage of this method? It will look something like this:
PersonFinder finder = new PersonFinder();
Employee employee = new Employee();
finder.FindPerson<Employee>(employee, 1);
See? I can't call method FindPerson if I don't provide an instance of the Employee class. But that's stupid! I can understand the following signature, without generic type:
public T FindPerson<T>(int id) {}
But there is no big difference for me where the type parameter will be: in method parameter or signature.
Can anyone point me what I missed?

P.S. By the way, the rest of the book is great :)

Reply With Quote