First, a bit of background of my question; I am writing a modular Server/Client type program in C#. I have a threaded processing system to handle my packets from a client queue, an example of what I am working with:
public delegate object ProcessPacket(object data);
public class QueueHandler
{
//Awesome functions/variables
private void Proccess()
{
object retPacket = client.ProcessPacket(obj);
NetworkCommon.Sendpacket(retPacket, _clientSocket);
}
//Even more awesome functions.
}
//Client ProcessPacket delegate
private static object ProcessPacket(object packet)
{
ReturnPacket ret = new ReturnPacket();
switch (packet.Command)
{
case Command.Login:
//Do login stuff
break;
case Command.Foo;
//Foo stuff
break;
case Command.Bar;
//Bar stuff
break;
default:
ret.Responce = CommandResponce.CommandNotRecognized;
}
return ret;
}
As you can guess, this isn't very extensible, and will be hard to manage with feature additions. My question is, What is a more practical way of this?
I thought of a List<string,TProcessCommand>
of sorts, assigning a custom attribute to the function then building that list on start up using reflection. But feel that may still be cumbersome to manage and possibly unneeded processing power each start up.
Another option I have considered is using the MEF, but I am having a hard time wrapping my head around how to identify between the commands without using Linq, which I am unfamiliar with.
[[EDIT]]
I just noticed in a MEF
example, the ExportMetadataAttribute
was used. I will give this a shot with my code.