I want to Concat two expressions for the final expression
Expression>
So I have created expression belwo code
It can be further simplified to:
var convertedExpression = Expression.Call(
memberExpression,
typeof(object).GetMethod("ToString"));
Instead of trying to cast to string, you could try casting to object then calling ToString(), as though you were doing:
var converted = member.ToString();
As an Expression, it will look something like this:
var convertedExpression = Expression.Call(
Expression.Convert(memberExpression, typeof(object)),
typeof(object).GetMethod("ToString"));
Rather than calling string.Concat(string, string)
, you could try calling string.Concat(object, object)
:
MethodInfo bodyContactMethod = typeof (string).GetMethod("Concat",
new[] { typeof(object), typeof(object) });
To expand on Richard Deeming's answer even though it's a little late.
Expression.Call(
typeof(string).GetMethod("Concat", new[] { typeof(object), typeof(object) }),
Expression.Convert(cons, typeof(object)),
Expression.Convert(memberExpression, typeof(object))
);
That should work just fine while allowing the signature to stay as you have it.