I ask similar question here , assume this type:
public class Product {
public string Name { get; set; }
public string Title { get; set; }
public string Cat
Try casting body.Member
to a PropertyInfo
public class HelperClass
{
public static void Property(Expression> expression)
{
var body = expression.Body as MemberExpression;
if (body == null)
{
throw new ArgumentException("'expression' should be a member expression");
}
var propertyInfo = (PropertyInfo)body.Member;
var propertyType = propertyInfo.PropertyType;
var propertyName = propertyInfo.Name;
}
}