I have something that looks similar to the following:
public class MyClass
{
private List<MyOjectMapping> mappings;
public void Start()
{
foreach (var mapping in mappings)
{
mapping.ObjectA.PropertyA.PropertyChanged += (s, e) =>
{
// do something with mapping.ObjectB
};
}
}
public void Stop()
{
// unhook events
}
}
public class MyObject : INotifyPropertyChanged
{
public object PropertyA;
public object PropertyB;
}
public class MyOjectMapping
{
public object SomeSortOfKey;
public MyObject ObjectA;
public MyObject ObjectB;
}
As you can see, I'm trying to perform some action on the foreach iterator inside the lambda event handler. This works, but doing it this way, I can't figure out how to unhook the events in the Stop() method.
How should I go about hooking up the PropertyChanged event so that I can unhook it later and still access the foreach iterator?
Thanks