using System.Collections.Generic;
public class ActionAttribute : Attribute
public ActionCode ActionCode { get; private set; }
public ActionAttribute(ActionCode code)
public Action(byte[] data)
protected string ReadMapleString()
[Action(ActionCode.Login)]
public class LoginAction : Action
public string Username { get; private set; }
public string Password { get; private set; }
public LoginAction(byte[] data)
this.Username = this.ReadMapleString();
this.Password = this.ReadMapleString();
static public void Login(LoginAction action)
Console.WriteLine("LoginAction.Login(LoginAction) called");
static public void Main()
var actionCode = ActionCode.Login;
OnReceiveData(actionCode, data);
Console.WriteLine("Complete.");
static public void OnReceiveData(ActionCode code, byte[] data)
var type = System.Reflection.Assembly.GetCallingAssembly()
t => t.GetCustomAttributes()
.OfType<ActionAttribute>()
.Where( a => a.ActionCode == code)
.GetMethods(BindingFlags.Static | BindingFlags.Public)
var instance = Activator.CreateInstance(type, new object[] { data });
member.Invoke(null, new object[] { instance });
static IEnumerable<Type> GetTypesWithActionAttribute(Assembly assembly)
foreach(Type type in assembly.GetTypes())
if (type.GetCustomAttributes(typeof(ActionAttribute), true).Length > 0)