16 Replies
if the return type is void, it's an
Action
Func
will always have a parameter, since it's by definition a delegate with a non-void return type
oh
you can'twhat would be the closest method alike?
basically, with more context
you either have to use
MethodInfo
, reflection checks, or multiple overloads, or wrap your delegates in a classi have an "event bus", that once passed a <random> function, with unknown parameters
it will execute without needing to know the parameters of given func
yeah the best way is to make an adapter class for that function
or an adapter delegate that casts the argument to the expected type
the method i was going down, was having a separate class for the arguments, and using the "argument stack" for the functions to use
haven't fully written the class out yet, but the event will have a callback that's overrode later on
is this sort of the method your referring to?
you'll have to box if you don't do generics throughout your whole event system
so kinda like this
wtf am i seeing 😂
im not too familiar with c# syntax lol
but if you don't want to box then the approach eill be completely different
i also dont know what boxing is, sorry lol
like this, if it makes it easier on the eyes
you can't make a generic event bus in C# that supports managed structs without boxing, even with unsafe, due to some unfortunate GC rules around references. It would only work with unmanaged structs + some unsafe things
but with boxing, or if your event data are classes, the wrapper I just showed should do just fine
this code isn't right tho, where's the only argument?
you aren't passing anything in the end
anyway, you might want something more straightforward
look into the adapter pattern
just a bland representation. i think i got it figured out sort of. appreciate your help g
np
Closed!