If your types share a base class or interface, you can constrain your method to that interface, and access members of the interface directly.

If they are unrelated types of T, then you might want to consider using a separate method overload for each type. This is far more maintainable than the mess that arises from checking the types inside of a method and handling each type individually.

That being said, you might want to consider just using Linq's Select method instead of your own ConvertData<T>. Select is intended for mapping operations - converting data from one form to another.

Related Articles