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
When LambdaExpression is known at compile time, could we compile it (resp generate Func<> at compile time)?
Following code does runtime compilation:
var formField = new FormField(() => myObj.Property1);
class FormField
{
private Func<object> _valueGetter;
public FormField(Expression<Func<object>> propertyExpression)
{
Name = ((MemberExpression)propertyExpression.Body).Member.Name;
_valueGetter= propertyExpression.Compile();
}
public string Name {get; }
public object Value => _valueGetter();
}
in order to avoid runtime compilation I would have to define both, Expression and Func:
var formField = new FormField(() => myObj.Property1, () => myObj.Property1);
but this could be done by the compiler.
alternatively, we the compile could just precompile the Expression so that calling propertyExpression.Compile() would be fast
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When LambdaExpression is known at compile time, could we compile it (resp generate
Func<>
at compile time)?Following code does runtime compilation:
in order to avoid runtime compilation I would have to define both, Expression and Func:
but this could be done by the compiler.
alternatively, we the compile could just precompile the Expression so that calling
propertyExpression.Compile()
would be fastBeta Was this translation helpful? Give feedback.
All reactions