c# - LINQ Expression Conversion / Concat from Int to string -


i want concat 2 expressions final expression

expression<func<t, string>> 

so have created expression belwo code works fine string types , if memberexpression int32 or datetime throwing exception

expression of type 'system.int32' cannot used parameter of type 'system.string' of method 'system.string concat(system.string, system.string)'

if convert expression

var conversion = expression.convert(memberexpression, typeof (string)); 

getting no coercion operator defined between types 'system.int32' , 'system.string'.

please me resolve

code

methodinfo bodycontactmethod = typeof (string).getmethod("concat",new[] {typeof (string), typeof (string)});  parameterexpression parameter = expression.parameter(typeof (t));  body = expression.call(bodycontactmethod, cons, memberexpression);  return expression.lambda<func<t, string>>(body, parameter); 

instead of trying cast string, try casting object calling tostring(), though doing:

var converted = member.tostring(); 

as expression, this:

var convertedexpression = expression.call(                      expression.convert(memberexpression, typeof(object)),                      typeof(object).getmethod("tostring")); 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -