On Saturday, 28 January 2017 at 09:05:13 UTC, rumbu wrote:
As long as your class has a default constructor, you can use
directly Object.factory(id):
public static NetworkMessage GetInstance(string id)
{
return cast(NetworkMessage)(Object.factory(id));
}
It isn't possible. My function when I receive data :
private void ReceivedData(char[] buffer)
{
BinaryReader reader = new BinaryReader();
uint id = reader.ReadUInt();
uint length = reader.ReadInt();
if(length > reader.Available.length)
{
//waiting for the rest
return;
}
NetworkMessage message =
ProtocolMessageManager.GetInstance(id);
message.Deserialize();
//.....
}