Dark
Dark
CC#
Created by Dark on 12/20/2022 in #help
❔ Dictionary of delegates for non-static functions. (Task & Action)
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.
17 replies
CC#
Created by Dark on 12/20/2022 in #help
❔ Dictionary of delegates for non-static functions. (Task & Action)
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 🙂
17 replies
CC#
Created by Dark on 12/20/2022 in #help
❔ Dictionary of delegates for non-static functions. (Task & Action)
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.
17 replies
CC#
Created by Dark on 12/20/2022 in #help
❔ Dictionary of delegates for non-static functions. (Task & Action)
when doing this code, I should be able to invoke OnLoginPacket for the correct PacketHandler object.
17 replies
CC#
Created by Dark on 12/20/2022 in #help
❔ Dictionary of delegates for non-static functions. (Task & Action)
here is an example of kind of what I'm trying todo.
public class anythinggoes
{
static Dictionary<_MAP_LOGIN_PROTOCOL, Delegate> loginPacketDef = new Dictionary<_MAP_LOGIN_PROTOCOL, Delegate>()
{
{LOGIN_PROTOCOL.LOGIN, new Action<_rcmRequestGateLogin>(PacketHandler.OnLoginPacket)},

};
}
public class PacketHandler//Packet handling
{
private SocketClient connection;
PacketHandler handler = null;
public PacketHandler(SocketClient connection)
{
//Code
}
public void SendPacket(byte[] data)
{
//Code
}
public void OnLoginPacket(_rcmRequestGateLogin request)
{
//Code
}
}
public class anythinggoes
{
static Dictionary<_MAP_LOGIN_PROTOCOL, Delegate> loginPacketDef = new Dictionary<_MAP_LOGIN_PROTOCOL, Delegate>()
{
{LOGIN_PROTOCOL.LOGIN, new Action<_rcmRequestGateLogin>(PacketHandler.OnLoginPacket)},

};
}
public class PacketHandler//Packet handling
{
private SocketClient connection;
PacketHandler handler = null;
public PacketHandler(SocketClient connection)
{
//Code
}
public void SendPacket(byte[] data)
{
//Code
}
public void OnLoginPacket(_rcmRequestGateLogin request)
{
//Code
}
}
17 replies
CC#
Created by Dark on 12/20/2022 in #help
❔ Dictionary of delegates for non-static functions. (Task & Action)
Also if any one has alternative methods I would love to know them as well! 🙂
17 replies