我可以使用罗斯林的编译时间code重写? [英] Can I use Roslyn for compile time code rewriting?
问题描述
例如我有
class Foo: INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
public int Bar {get;set;}
}
我可以得到Foo类AST和重写酒吧,在编译时,以
Can I get the Foo class AST and rewrite Bar, in compile time, to
public string Bar
{
get { return this.bar; }
set
{
if (value != this.bar)
{
this.phoneNumberValue = value;
PropertyChanged(this, new PropertyChangedEventArgs("Bar"));
}
}
}
推荐答案
编译时间重写不是直接由罗斯林今天支持,但语法和语义的转换肯定是。其实,看一看列入CTP看到你想要做什么东西ImplementNotifyPropertyChanged样本。样品被实现为在设计时间改造和IDE的功能,但你可以提取逻辑,使其成为类似的东西编译之前重写文件pre-生成任务。
Compile time re-writing isn't directly supported by Roslyn today, but syntactic and semantic transformations definitely are. In fact, take a look at the "ImplementNotifyPropertyChanged" sample included in the CTP to see something of what you want to do. The sample is implemented as a design time transformation in and IDE feature, but you can extract the logic and make it into something like a pre-build task that rewrites files before compilation.
这篇关于我可以使用罗斯林的编译时间code重写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!