Rettoph
Generically creating a delegate from a MethodInfo with parameter upcasting
I have been pursuing a possible solution by creating a
DynamicMethod
- the proof of concept i have at the moment looks like so:
But... im already starting to see how much work its going to take to achieve my goal. Is this already a solved problem? I feel like i cant be the first to want this - is there a better solution than the IL & reflection madness ive embarked on? Perhaps a usefil library that already did the hard work for me?
Any ideas would be hugely appreciated. thanks!2 replies
Implementing scripting in a game engine
ive not used it a ton, but Moonsharp might be a good option https://github.com/moonsharp-devs/moonsharp
41 replies
Contravariant Help
After asking around on the MonoGame server one thing ive found is that my question probably wasnt very clear
My question is about contravariance at its core. Given the code above, the following is valid:
As
MySubscriber
implements both ISubscriber<MessageA>
and ISubscriber<MessageB>
, and the ISubscriber
interfaces utilizes the in keyword i can cast MySubscriber
directly to ISubscriber<MessageC>
. The issue is i want to be able to invoke all ISubscriber
implementations that can be casted to ISubscriber<MessageC>
.
Doing ((ISubscriber<MessageC>)new MySubscriber()).Process()
is valid, but only gives me the first one.
Its an issue because ISubscriber<MessageC>
is ambiguous, there are two interfaces that can meet that criteria. Even with reflection i cant seem to find a way to invoke the ISubscriber<MessageB>
implementation8 replies