Skip to content

Using FEC to compile a property setter with an enum value sets the property to random values #172

@CodingGorilla

Description

@CodingGorilla

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions