I need to expose an event of an instance of a class using a property from a different class.
If I expose an event defined in MyClass with a property defined in the same MyClass, so that the event works like a backing field, everything is fine:
private event EventHandler<EventArgs> _somethingHappened;
public EventHandler<EventArgs> SomethingHappened
{
get => _somethingHappened;
}
Could sound weird, but it might be useful for some reason.
But if I expose (in the same manner) an event defined in AnotherClass, accessed by an instance of that AnotherClass, as follows:
public EventHandler<EventArgs> SomethingStarted
{
get => Instance.Started;
}
where Instance is the instance of that AnotherClass and Instance.Started is defined in AnotherClass as follows:
public event EventHandler<EventArgs> Started;
then I get the error: "The event can only appear on the left hand side".
I just don't get why the first case is allowed and the second is not, although they seem very similar.