I have the following C# class:
public class SignInViewModel : ISwitchable
{
IChildViewModelFactory _factory;
// Implement ISwitchable interface.
public event EventHandler<object> SwitchEvent;
public SignInViewModel(IChildViewModelFactory factory)
{
_factory = factory;
}
...
}
When I inspect value in the Visual Studio 2019 debugger, I cannot see the SwitchEvent field as a member:
((ISwitchable)value).SwitchEvent = ChildViewModel_SwitchEvent; // value is SignInViewModel instance.
I tried the following, but got the same result:
ISwitchable temp = (ISwitchable)value;
temp.SwitchEvent = ChildViewModel_SwitchEvent;
temp only shows the _factory and SignInViewModel() ctor as class members.
How can I see SwitchEvent, the event implementating the interface?
CodePudding user response:
SwitchEvent is not a field. It is an event and has no value but assigned handler method
What you need to do is to invoke your event like this
if (SwitchEvent != null)
(SwitchEvent(this); // 'this' is a sender
Check this out - how to view event handler assignment
