dot*_*ter 16 c# metaprogramming compiler-as-a-service roslyn
比如我有
class Foo: INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
public int Bar {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我可以在编译时获取Foo类AST并重写Bar
public string Bar
{
get { return this.bar; }
set
{
if (value != this.bar)
{
this.phoneNumberValue = value;
PropertyChanged(this, new PropertyChangedEventArgs("Bar"));
}
}
}
Run Code Online (Sandbox Code Playgroud)
.
Kev*_*lch 16
Roslyn今天没有直接支持编译时重写,但语法和语义转换肯定是.实际上,请查看CTP中包含的"ImplementNotifyPropertyChanged"示例,以查看您要执行的操作.该示例在IDE功能中实现为设计时转换,但您可以提取逻辑并使其成为类似于在编译之前重写文件的预构建任务.
| 归档时间: |
|
| 查看次数: |
4042 次 |
| 最近记录: |