jeudi 28 juillet 2022

C# How to subscribe to an internal Action

How do I use reflection to subscribe, from a class, to a different class internal Action?

Such as

public class SneakyClass : Element
{
    internal Action<Trunk> OnConnect;
}
public class ResponderClass : Thing
{
    public SneakyClass OtherClass;

    public ResponderClass()
    {
        // doesn't work since the target is internal
        OtherClass.OnConnect += Callback;
    }

    public void Callback(Trunk t)
    {
        // do things
    }
}




Aucun commentaire:

Enregistrer un commentaire