❔ Dictionary of delegates for non-static functions. (Task & Action)
I'm trying to write a dictionary for delegates that when specific values are passed so I can invoke the delegate.
Currently code is written with a switch wanted todo with delegates though.
EX: Socks 5 packet is received, It calls the packet handler, Packet handle will check if packet exists in dictionary and invoke the delegate associated with it.
When this delegate is invoked I need it to know the object of the client so it's executing on correct client. So I need a way to pass what client/connection it is currently invoking this on, Non-static objects that are instantiated when a connection is made.
I would like to do this without using static functions and passing objects as parameter.
Sorry if this don't make sense not sure how to explain what I'm trying todo.
11 Replies
Also if any one has alternative methods I would love to know them as well! 🙂
do you mean remote procedure call?
@Dark You want to call the the Client's function instead of calling a static function delegate, right?
I feel like an example would really help here (What do you have right now etc., maybe some pseudo code of where you want to get to)
here is an example of kind of what I'm trying todo.
when doing this code, I should be able to invoke OnLoginPacket for the correct PacketHandler object.
I want to call from a static Dictionary. I will be running the actual directory lookup from the PacketHandler to Invoke the code. I just need a way to write it so it's valid and to pass PacketHandler/this.
@Dark
You can do
You would need to add
Handler
attribute on your handler methodsyes that's just RPC
use a library
By looks of it if I'm understanding code correctly this is exactly what I needed, Thank you so much! I will let you know if it works for me later today 🙂
This code does work! Thank you @Kouhai, I realize now that I did miss some details I did have to modify some of this but I managed to make it work for Actions. I do have a question though. Is there a way to use this with Delegate instead of Action? I will have times when I'm trying todo a Func or Action because I have some that have return types.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.@Dark Sorry was away
You can do something like this
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.