I have the following problem:
I have a class called File
and I want this class to inform another class when something special happened, but File
should not have a reference to the class which should be informed. I think this is the same problem which the INotifyPropertyChanged
-Interface solves. My only workaround is a static list which contains the instances of the class which should be informed and a static method of this class, but I think this is not the smartest way to do it.
So, which concept does PropertyChanged
use?
Edit:
Lets assume that the class which should react (be informed) is called FileManager
, has an implicit event called FinishedReading
and this class is only instantiated one time.
How can I bind the FileManager
s FinishedReading
-Event to the method FinishReading()
of the class File
, if File
should not have any reference to FileManager
s instance?
I already tried to pass the FileManager
s Event as parameter, but it didn`t work.
Example:
[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestClass]
public class FileManager
{
public delegate void MyDelegate();
public event MyDelegate FinishedReading;
}
[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestClass]
public class File
{
// Whats the exact Data-Type of the FinishedReading-Event?
public File(FileManager.MyDelegate eventInstance)
{
eventInstance += FinishReading;
}
public void FinishReading()
{
//
}
}