I have some objects like user, address and so on, and Im converting them to business objects using extension methods:
public static UserModel ToPresentationForm(this User pUser)
{
return new UserModel
{
...
map data
...
};
}
Also I need to convert strongly typed collections and usually I have the following code:
public static List<UserModel> ToPresentationForm(this List<User> pUserColl)
{
return pUserColl.Select(x => x.ToPresentationForm()).ToList();
}
I was thinking, what if I add some interface, like IPresentationForms and will be able to use it, to write method like
public static List<T> ToPresentationForm(this List<IPresentationForms> pTemplate)
{
return pUserColl.Select(x => x.ToPresentationForm()).ToList();
}
Not sure how to provide parameter to method type to make it generic. So the actual question is, how to do that.
P.S. Im using C# 4.0