Skip to content

Instantly share code, notes, and snippets.

@pollend
Created July 16, 2020 06:13
Show Gist options
  • Save pollend/cd6fdb2c8dcfbf2e022b255763339025 to your computer and use it in GitHub Desktop.
Save pollend/cd6fdb2c8dcfbf2e022b255763339025 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Reflection;
namespace TEST
{
internal class Program
{
public interface ITestObject
{
}
public class obja: ITestObject
{
}
public class NetworkHandler: Attribute
{
}
public static class NPCHandlers
{
[NetworkHandler]
public static void Configure(obja packet)
{
int x = 0;
x++;
}
}
public delegate void NetworkEventHandler<ITarget>(ITarget target) where ITarget: ITestObject;
public static void Main(string[] args)
{
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type type in assembly.GetTypes())
{
MethodInfo[] methods = type.GetMethods();
foreach (var method in methods)
{
if (method.GetCustomAttributes(true).OfType<NetworkHandler>().Count() > 0)
{
ParameterInfo[] info = method.GetParameters();
// typeof(NetworkEventHandler<>).MakeGenericType(info[0].GetType()).CR.CreateDelegate(method.GetType(), method);
Delegate handler = Delegate.CreateDelegate(typeof(NetworkEventHandler<>).MakeGenericType(info[0].ParameterType), method) ;
handler.DynamicInvoke(new obja());
// NetworkEventHandler<ITestObject> eventHandler = Delegate.CreateDelegate(typeof(NetworkEventHandler<>).MakeGenericType(info[0].GetType()), null, method);
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment