mercredi 26 avril 2017

Invoke constructor on reflected type with callback of said type

I have a class X with some constructor that has a callback, where the callback passes back the instance of X:

class X
{
    public X(Action<X> callback) { ... }
}

Since I don't have access to the class X (it's protected in another assembly), I'm using reflection to obtain the type and the constructor, so far so good. And don't worry, something like this won't be used in production, it's just for testing purposes.

However, how can I type the callback if I don't have access to X statically? An Action gives casting errors on invocation (understandably). Note I don't actually care about the X type, an object representation is fine.

Thanks





Aucun commentaire:

Enregistrer un commentaire