I want to define a function, such as the function of the MVC TextBoxFor extension template
The interesting thing for this function is that I do not need to specify the TProperty type. How can I set this in my function definition.
My code looks like this:
public class Helper<TItem>
{
public string GetMemberName(Expression<Func<TItem, TProperty>> expression)
{
... returns TProperty.Name
}
}
The actual problem is that this does not compile ... because it cannot find the TProperty type.
As a result, I want to define a class once with a type ... and then use the GetMemberName function to get the name of each member, as in the MVCframework.
Helper<Employee> h = new Helper<Employee>();
string name = h.GetMemberName(e=>e.Name);
....
I do not want me to be forced to specify the type of TProperty when writing code. In principle, it can be any object.
Thank,
Radu