如何公开在另一个 class 中声明的 C# Action

How can I expose a C# Action declared in another class

我想在 public class

中公开在内部 class 中声明的 Action
internal class A
{ 
     public Action OnEvent { get; set; }
}

public class B
{
     private A a = new A();

     public Action OnEvent 
     {
         get => a.OnEvent;
         set => a.OnEvent += value;    <- this is not correct

     }
}

我正在寻找 属性 getter/setter 允许编写如下代码:

var b = new B();
b.OnEvent += DoSomething;  // this should add DoSomething to B.a.OnEvent
...
b.OnEvent -= DoSomething;  // this should remove DoSomething from B.a.OnEvent

编辑 一种解决方案是添加

void Add(Action handler) 
{ a.OnEvent += handler}

void Remove(Action handler) 
{ a.OnEvent -= handler }

但我想使用 += & -= 语法

找到了

public event Action OnEvent
    {
        add { a.OnEvent += value; }
        remove { a.OnEvent -= value; }
    }