Nemerle扩建物业

时间:2011-12-12 15:05:30

标签: nemerle

最近讨论了将扩展属性添加到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;
  }
}

注意:module == static class

您怎么看?

1 个答案:

答案 0 :(得分:0)

我不喜欢它因为重复:

  1. 你应该在两点指定Type2,
  2. 您应该在两点指定PropName。
  3. 因此重构可能会稍微复杂一些。以下方法怎么样?

    module MExtension
    {
      property PropName(this arg : Type1) : Type2
      {
        get
        {
          ...
        }
        set
        {
          ... = value
        }
      }
    }
    

    甚至autoproperty:

    module MExtension
    {
      property PropName(this arg : Type1) : Type2 { get; set; }
    }