Can I create an automatic property (no private member) with get and set code?

前端 未结 4 541
后悔当初
后悔当初 2021-01-24 02:14

In c#, I can do this:

public int Foo { get; set; }

Which is nice. But as soon as I want to do anything in the getter or setter, I have to chang

4条回答
  •  不思量自难忘°
    2021-01-24 02:28

    As others have said, there is no builtin way to do this.

    You could achieve something kind of similar with PostSharp. But I'm not sure its worth the effort.

    [AfterSet(DoSomething)]
    public int Foo {
        get;
        set;
    }
    

提交回复
热议问题