© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•11mo ago•
54 replies
Adise

✅ 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
MessageHandler
class I have this dictionary:
    public static Dictionary<ServerPackets, MessageListener<IPayload>> messageListeners = new();
    public static Dictionary<ServerPackets, MessageListener<IPayload>> messageListeners = new();
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

❔ class instance creation
C#CC# / help
4y ago
Class Libraries Project Reference
C#CC# / help
2y ago
✅ How do I reference a specific private instance of a class
C#CC# / help
2y ago
Dynamically assign values to class instance properties / Indexing class instance properties
C#CC# / help
2y ago