.net - Workaround for lack of 'nameof' operator in C# for type-safe databinding? -
There are many emotions to include a
nameof
operator in C #. An example of how this operator will work will return name (customer name)
string "name"
. I have a domain object. And I have to pair it. And I need the names of properties to be strings I and I want them to be type-safe.
I remember that the workaround is coming to NAT 3.5 which provides functionality of nameof
and includes lambda expressions. However, I am unable to locate this solution. Can someone provide this solution for me?
If possible, then. I am also interested in implementing the functionality of the nameof
in NET 2.0.
This code basically does this:
class programs {Static void main () {var propName = Nameof & lt; SampleClass & gt; Property (E => E. Name); Console.WriteLine (propName); }} Name of the public class & lt; T & gt; {Static String property & lt; TProp & gt; (Expression & lt; funk & lt; t, tprop & gt; & gt; expression) {var body = expression. As a member expression; If (body == faucet) throwing the new argument exception ("'expression must be a member expression'); return body.member .name;}}
(Of course this is 3.5 code. ..)
Comments
Post a Comment