Say we have the following C # class
public class Class1 { protected event EventHandler ProtectedEvent; protected virtual void OverrideMe() { } }
It seems impossible to use ProtectedEvent in F #.
type HelpMe() as this = inherit Class1() do printfn "%A" this.ProtectedEvent member x.HookEvents() = printfn "%A" x.ProtectedEvent member private x.HookEvents2() = printfn "%A" x.ProtectedEvent override x.OverrideMe() = printfn "%A" x.ProtectedEvent
In this example, I tried calling printfn on it, as there are several ways to hook events in F #, and I would like to be clear that this is just a reference to the event in general, which causes the problem.
In each of the above cases, the compiler complains of the following error:
A protected element is invoked or "base" is used. This is only allowed in the immediate implementation of members, since they can avoid the scope of the object.
I understand this mistake that causes her and her purpose. Usually the work around is to end the call in a private member that works great with methods - but this doesn't seem to work with events. No matter what I try to do, it is impossible to use protected events in F # unless I resort to something with reflection or make some changes to the base class (which is impossible in my case).
Note that I also tried all possible combinations of using base , this and x .
Am I doing something wrong?
source share