p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional .NET 2.0 Generics (http://p2p.wrox.com/forumdisplay.php?f=218)
-   -   Guidelines Item 3: Replace System.Type with Type (http://p2p.wrox.com/showthread.php?t=61280)

Ixtlia August 19th, 2007 04:09 AM

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:
Code:

public T FindPerson<T>(T personType, int id) {}
instead of
Code:

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:
Code:

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:
Code:

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 :)



All times are GMT -4. The time now is 06:13 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.