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

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -