© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
21 replies
Killers0992

✅ Get delegate from event

I got class
public static class Events
{
  public static PlayerEvents Player { get; } = new PlayerEvents();
}
public static class Events
{
  public static PlayerEvents Player { get; } = new PlayerEvents();
}

and PlayerEvents class contains
public class PlayerEvents
{
    public event Event<PlayerLeftServer> Leaving;

    public event Event<PlayerLeftServer> Left;
}
public class PlayerEvents
{
    public event Event<PlayerLeftServer> Leaving;

    public event Event<PlayerLeftServer> Left;
}


I want to get delegate from Leaving/Left event but seems like while trying to get value its null? idk

            foreach (var property in typeof(Events).GetProperties(BindingFlags.Public | BindingFlags.Static))
            {
                foreach (var ev in property.PropertyType.GetEvents())
                {
                    FieldInfo evField = property.PropertyType.GetField(ev.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField);

                    // GetValue returns null
                    Debug.Log(evField.GetValue(property.GetValue(null, null)));
                }
            }
            foreach (var property in typeof(Events).GetProperties(BindingFlags.Public | BindingFlags.Static))
            {
                foreach (var ev in property.PropertyType.GetEvents())
                {
                    FieldInfo evField = property.PropertyType.GetField(ev.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField);

                    // GetValue returns null
                    Debug.Log(evField.GetValue(property.GetValue(null, null)));
                }
            }
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

Similar Threads

✅ delegate and event IMPLEMENTATION question..
C#CC# / help
4y ago
❔ my delegate event is not raising the event
C#CC# / help
4y ago
❔ CS0123No overload for 'CanvasMain_PreviewMouseMove' matches delegate for 'EventMouseHandler'
C#CC# / help
3y ago
✅ Acces delegate type from another script
C#CC# / help
3y ago