Adise
Adise
CC#
Created by Adise on 4/6/2025 in #help
✅ Class instance reference
I'm having some issues figuring out why my code is behaving like it's taking a "snapshot" of an instance instead of directly referencing it. So I created a custom attribute so that I could check a class for methods with it and add the methods to the list. I had to "register" my methods after creating the instance so that they could access the instance members, and so in the class constructor I added:
public UdpConnection()
{
MessageHandler.RegisterListeners(typeof(UdpConnection), this);
}
public UdpConnection()
{
MessageHandler.RegisterListeners(typeof(UdpConnection), this);
}
For context, this is how a listener looks:
[MessageListener(ServerPackets.S_UdpPort)]
private void AssignLocalPort(S_UdpPortPayload payload)
{
#region AssignLocalPort
// Code here
#endregion
}
[MessageListener(ServerPackets.S_UdpPort)]
private void AssignLocalPort(S_UdpPortPayload payload)
{
#region AssignLocalPort
// Code here
#endregion
}
In my MessageHandler class I have this dictionary:
public static Dictionary<ServerPackets, MessageListener<IPayload>> messageListeners = new();
public static Dictionary<ServerPackets, MessageListener<IPayload>> messageListeners = new();
55 replies