Action <T>等效于属性

Jon*_*Jon 5 .net c# delegates c#-4.0

我有一个类实例化两个实现接口的类.我想要一个类通知另一个类,某些东西没问题.我可以用Action执行它然后在类中使用私有变量但是想知道是否有直接的方法来使用属性,以便当属性的值更改时它更新另一个类的属性.

例如:

public class MyClass
{
  public ILogger Logger {get;set;}
  public ILogic Logic {get;set;}

  private Form MyWinform;

  public void Setup()
  {
    MyWinform = new MyWinform();
    MyWinform.StartBatch += Logger.CreateFile; //Create file when user presses start

    //How can I set a property on ILogic to be AllOk once ILogger says so??

    //I could use an Action so that once all is ok I call IDecidedAlOK in ILogger which
    //can then assign a private bool variable inside the class

    Logic.ItsOKMethodSoSetVariableToTrue = Logger.IDecidedAllOKMethod;

  }

  public void DataIn(string Value)
  {
     Logic.DataIn(Value);
  }

  public void CreateInstances()
  {
     Logger = new FileLogger();
     Logic = new MyLogic();
  }

}

public class MyLogic : ILogic
{
   public void DataIn(string Value)
  {
     //I want to check that all is ok before I do anything

     //if (!AllOK) 
     //return;

     //Do stuff
  }
}
Run Code Online (Sandbox Code Playgroud)

Mic*_* B. 3

实现INotifyPropertyChanged接口并订阅PropertyChanged事件