It is relatively easy to create a lambda function which will return the value of the property to something, even Including deep properties. ..
And it can be said like this ...
string categoryName = getCategoryName (this.category);
However, the resulting result above is given only (or originally used to create a function expression), Anyone can provide easy way to create anti-action ...
Action & lt; Category, string & gt; SetCategoryName = New Action & lt; Category, string & gt; ((C, s) => c.Name = s);
... which will enable the same property value to be set as follows?
setCategoryName (this.category, "");
Note that I'm looking for a way to implement the program with verb or expression - I hope I have shown that I already know how to make it manually Go.
I'm open to the answer Works in both 3.5 and 4.0.
Thank you.
UPDATE:
Maybe I am not clear my question is, let me show you more clearly what I am trying to do.
I have the following method (which I have created for the purpose of this question) ...
zero doLambdaStuff < TOBject, TValue & gt; (Tobias obj, expression & lt; Func & amp; tt; TObject, TValu>> expression) {Func & lt; Tobject, TValue & gt; GetValue = expression Compile (); TV accessories = Milan (OBJ); Expression and lieutenant; Action & Lieutenant; Tobagect, TVLue & gt; & Gt; Assignment expedition = (O, V) = & gt; Expression & lieutenant; Tobjject & gt; Essen (expression, expression. Constant (v, typef (TVLu))); Action & Lieutenant; Tobagect, TVLue & gt; SetValue = Assignment. Expression.compil (); Set value (obje, luggage); }
Am I seeing how do I create an "assignment expression" within the code, so that I can compile it in the set value? I think it is related to the expression. Assin, but I can not just make the right combination of parameters to complete the code.
The last outcome is to be able to call
category category = * & lt; Obtain object from somewhere & gt; *; This.DoLambdaStuff (Category, C = & gt; c.Name);
and in turn, the category object's "name" will create a waiter and setter for the property.
The version is compiled above, but when I call the set value
>
Zero DoLambdaStuff & lt; TOBject, TValue & gt; (Tobias obj, expression & lt; Func & lt; Tobject, TValue & gt; Expression) {Func & lt; Tobject, TValue & gt; GetValue = expression Compile (); TV accessories = Milan (OBJ); Var p = expression.Pameter (typef (TVLu), "V"); Expression and lieutenant; Action & Lieutenant; Tobagect, TVLue & gt; & Gt; Assignment expression = expression Lambda & lieutenant; Action & LT; TubyXight, TVLue & gt; & Gt; (Expression. Escin (expression.bdi, p), expression. Parameter [0], p); Action & Lieutenant; Tobagect, TVLue & gt; SetValue = Assignment. Expression.compil (); Set value (obje, luggage); }
Comments
Post a Comment