static Handler()
{
var asm = Assembly.GetExecutingAssembly();
var types = asm.GetTypes();
foreach (var type in types)
{
if (!type.IsAbstract)
continue;
if (!type.IsPublic)
continue;
var methods = type.GetMethods();
foreach (var method in methods)
{
if (!method.IsPublic)
continue;
var attrs = (ParserAttribute[])method.GetCustomAttributes(typeof(ParserAttribute),
false);
if (attrs.Length <= 0)
continue;
var parms = method.GetParameters();
if (parms.Length <= 0)
continue;
if (parms[0].ParameterType != typeof(Packet))
continue;
foreach (var attr in attrs)
{
var opc = attr.Opcode;
var del = (Action<Packet>)Delegate.CreateDelegate(typeof(Action<Packet>), method);
Handlers[opc] = del;
}
}
}
}