Convert a property getter to a setter
Convert a property getter to a setter
In the process of adding some strongly-typed extensions to the official MongoDB C# driver I needed some code to convert a property getter into a property setter. The following static method does that, turning e => e.Field into an Action method you can call to set the value of ‘Field’.
[csharp] /// \
var parameterT = Expression.Parameter(typeof(T), “x”); var parameterU = Expression.Parameter(typeof(U), “y”);
var newExpression = Expression.Lambda\<Action\
return newExpression.Compile(); } [/csharp]
Fri Sep 16 2011 04:52:40 GMT-0700 (Pacific Daylight Time)
Next page: Remember Everything ... a long-term project
Previous page: What if ... you could define and query an Ontology using natural language?