Property - aka infoof - through Rosyln?

A few years ago, Eric Lippert blogged on the hypothetical info operator, which allows you to get information about a method / properties at compile time, rather than at run time. Basically saying that it is a good pony, but not a unicorn ....

I read a little about the ability of Rosyln to rewrite code at compile time, how difficult would it be to implement information using Roslyn?

EDIT: I thought this might be a way to get everything Eric said, what you were thinking about, but I should have broken functions a bit if it werenโ€™t.

  • Get the name of the property.
  • Get the type of property.
  • Get accessors properties.
  • Get the name of the method.
  • Get everything he had in mind with infoof ...

In refactoring mode, which is checked at compile time. For me personally, 1 covers about 90% of what I would use (the new subscriber information attribute to get the name of the caller can actually cover about 60%, but, of course, if there was a method that worked both inside and outside the method which would be preferable).

+3
roslyn
Jun 29 2018-12-12T00:
source share
1 answer

You can easily use Roslyn to rewrite one valid C # code into another valid C # code. But it was not intended to add extensions to the language.

Roslyn also handles the wrong code (it should, if you want to use it for IntelliSense on an incomplete line), but since it is invalid, there is no guarantee that it will do it right (because it is not clear what exactly the "right" means). In addition, I think that the structure that he will use for infoof will not be very convenient for you.

To summarize: this is not what Roslyn is intended to use, and it is probably a bad idea. But I think that this cannot be done with Roslyn.

+4
Jun 29 '12 at 5:32
source share



All Articles