Reflection in D

medhi558 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 28 01:25:56 PST 2017


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();

     //.....
}



More information about the Digitalmars-d-learn mailing list