通过Rosyln - 又名infoof的财产? [英] Property-of aka infoof -- via Rosyln?

查看:227
本文介绍了通过Rosyln - 又名infoof的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年前埃里克利珀的博客约一个假设infoof运营商,它会让你获得在运行时编译时我代替方法/属性信息。基本上说,这是一个不错的小马,但没有麒麟......

A few years ago Eric Lippert blogged about a hypothetical infoof operator that would allow you to get method/property information at compile time i stead of at runtime. Basically saying that it's a nice pony, but no unicorn....

我读了一些关于Rosyln的重写你的code在编译时能力,多么困难将是实现infoof使用罗斯林?

I read a bit about Rosyln's ability to rewrite your code at compile time, how difficult would it be to implement infoof using Roslyn?

编辑:我想这可能是一个办法让一切埃里克说你他们在想什么,但我应该细分功能的情况下有点它不是

I thought this might be a way to get everything Eric said you they were thinking about, but I should have broken down the features a bit in case it wasn't.

  1. 获取属性名称。
  2. 获取属性类型。
  3. 在获取属性访问器。
  4. 获取方法的名称。
  5. 在获得的一切,他意思infoof ...

在重构安全的方式,即在编译时验证。就我个人而言,1占地约90%的我真的用什么(新主叫方信息属性得到一个来电者的名字实际上可以覆盖约60%,当然,如果有是工作内外的方法以外的方法,这将是preferable)。

In a refactoring-safe way, that gets verified at compile time. For me personally, 1 covers about 90% of what I would actually use (the new caller info attribute for getting a callers name can actually cover about 60%, but of course if there was a way that worked both inside and outside of the method, that would be preferable).

推荐答案

您可以轻松地使用罗斯林重写有一个有效的C#code到另一个有效的C#code。但它并不意味着添加的语言扩展。

You can easily use Roslyn to rewrite one valid C# code into another valid C# code. But it's not meant for adding extensions to the language.

罗斯林的确实的解析无效code太(它必须,如果你想在一个不完整的线路使用它的智能感知),但因为它是无效的,也不能保证它会做它正确(因为它目前还不清楚究竟是什么正确的意思)。另外,我认为它会使用 infoof 的结构不会对你非常方便。

Roslyn does parse invalid code too (it has to, if you want to use it for IntelliSense on an incomplete line), but since it's invalid, there is no guarantee it will do it correctly (because it's not clear what exactly does "correctly" mean). Also, I think the structure that it will use for infoof won't be very convenient for you.

要总结一下:这不是什么罗斯林的目的是用于和做它可能是一个坏主意。但我认为这不是不可能使用罗斯林做到这一点。

To summarize: this is not what Roslyn is meant to be used for and doing it is probably a bad idea. But I think it's not impossible to do this using Roslyn.

这篇关于通过Rosyln - 又名infoof的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆