Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# expression func automatically select return type

// If property is something like an int or double and you want an object,
// you need to manually convert it to an object via another expression.
var parameter = Expression.Parameter(typeof(T));
var body = Expression.Property(parameter, propertyName);
var converted = Expression.Convert(body, typeof(object));
return Expression.Lambda<Func<T, object>>(converted, parameter);
 
PREVIOUS NEXT
Tagged: #expression #func #automatically #select #return #type
ADD COMMENT
Topic
Name
7+7 =