NN_
NN_

Reputation: 1593

Nemerle Extension Property

Recently there was a discussion about adding Extension Property to Nemerle language. But the syntax is unclear.

Updated proposed syntax:

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;
  }
}

Note: module == static class

What do you think ?

Upvotes: 2

Views: 286

Answers (1)

ie.
ie.

Reputation: 6101

I don't like it because of duplication:

  1. you should specify Type2 in two points,
  2. you should specify PropName in two points.

So the refactoring can be slightly complicated. How about the following approach?

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

or even autoproperty:

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

Upvotes: 0

Related Questions