最近有一场关于在Nemerle语言中添加扩展属性的讨论。但其语法尚不清楚。
更新了建议的语法:
module MExtension
{
[ExtensionProperty(string)] public StringProp : int { get; set; }
[ExtensionProperty(int)] public IntProp : string { get { "abc" } }
}
module MTest
{
F() : void
{
def x : int = "ab".StringProp;
"abc".StringProp = 100;
def y : string = 10.IntProp;
}
}注意:模块==静态类
你觉得呢?
发布于 2011-12-13 16:54:40
我不喜欢它,因为重复:
所以重构可能会稍微复杂一些。下面的方法怎么样?
module MExtension
{
property PropName(this arg : Type1) : Type2
{
get
{
...
}
set
{
... = value
}
}
}甚至是autoproperty:
module MExtension
{
property PropName(this arg : Type1) : Type2 { get; set; }
}https://stackoverflow.com/questions/8476336
复制相似问题