Getting names of local variables (and parameters) at run-time through lambda expressions

后端 未结 3 1578
情话喂你
情话喂你 2020-12-03 10:40

I’m interested in retrieving the names of local variables (and parameters) at run-time in a refactor-safe manner. I have the following extension method:

publ         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-03 11:08

    This is a behavior you should not rely upon.

    Take a look at Abuse of C# lambda expressions or Syntax brilliance?

    Now read the comments from Eric Lippert who is on the C# design team. They include:

    I just asked Anders (and the rest of the design team) what they thought. Let's just say the results would not be printable in a family-friendly newspaper

    and

    As for why this is horrid, we could start with unobvious, clever (remember, clever is bad, clever code is hard to maintain), not at all within the by-design use cases envisaged by the designers of lambdas, slow, brittle, unportable, and unnecessary

    From these statements I would say that it will not become a documented or supported behavior.

提交回复
热议问题