I\'m making a server library in which the packet association is done by enum.
public enum ServerOperationCode : byte
{
LoginResponse = 0x00,
Selectio
How about using static Dictionary and a virtual method to retrieve the static dictionaries in the inherited classes?
Like the follow for your case:
public abstract class Operation
{
protected abstract Dictionary getCodeTable();
public int returnOpCode(string request){ return getCodeTable()[request]; }
}
public class ServerOperation : Operation
{
Dictionary serverOpCodeTable = new Dictionary()
{
{"LoginResponse", 0x00,},
{"SelectionResponse", 0x01},
{"BlahBlahResponse", 0x02}
};
protected override Dictionary getCodeTable()
{
return serverOpCodeTable;
}
}
public class ClientOperation : Operation
{
Dictionary cilentOpCodeTable = new Dictionary()
{
{"LoginResponse", 0x00,},
{"SelectionResponse", 0x01},
{"BlahBlahResponse", 0x02}
};
protected override Dictionary getCodeTable()
{
return cilentOpCodeTable;
}
}