You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following code that I use to do some simple mapping between instances:
public static Action<TEntity, TProperty> CreateSetter<TProperty>(Expression<Func<TEntity, TProperty>> property)
{
var propertyInfo = GetProperty(property);
var instance = Expression.Parameter(typeof(TEntity), "instance");
var parameter = Expression.Parameter(typeof(TProperty), "param");
var body = Expression.Call(instance, propertyInfo.GetSetMethod(), parameter);
var parameters = new[] { instance, parameter };
return Expression.Lambda<Action<TEntity, TProperty>>(body, parameters).CompileFast();
}
This works for most properties, but when I use it with one (that I know of) property which has an enum type, the value ends up being set to random integers that are not a part of the actual enum. Removing FEC and just using .Compile() seems to solve the problem.