I have written a simple extension method for HtmlHelper class like
public static string GetExpressionNames<TModel>(this HtmlHelper<TModel> helper,params Expression<Func<TModel,object>>[] args) where TModel:class
{
string returnStr = string.Empty;
int i = 0;
foreach (var x in args)
{
returnStr += (++i).ToString() + ExpressionHelper.GetExpressionText(x) + "<br/>";
}
return returnStr;
}
Currently, it's just accepting array of LambdaExpressions defined on Model properties (returning object) and add their expression text to a string which is then returned by this function. The problem is that, for string type properties it's working fine, but for int properties it's returning the empty string as expression text. The reason is that for expression that returns int values the body of expression looks like following image:
but for strings, its like
I think convert method is expressions that return integar values is causing the empty string to be returned as Expression text. How can I get around this problem? I just need original expression text i.e Id for Convert(x.id) and Name for x.Name; it does not matter how it is processing it at the back end.