Reflection in D
medhi558 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 28 12:51:29 PST 2017
thank you, the second method works perfectly.
I have one last problem, I start thread and in thread
Protocol.GetInstance(id) return null while in main thread it
works.
My class :
class ProtocolMessageManager
{
private static TypeInfo_Class[uint] m_types;
shared static this()
{
foreach(mod; ModuleInfo)
{
foreach(TypeInfo_Class lc; mod.localClasses)
{
if(lc.base is typeid(NetworkMessage))
{
NetworkMessage c = cast(NetworkMessage)lc.create();
ProtocolMessageManager.m_types[c.MessageId] = lc;
}
}
}
}
public static NetworkMessage GetInstance(uint id)
{
auto v = (id in ProtocolMessageManager.m_types);
if (v !is null)
return
cast(NetworkMessage)ProtocolMessageManager.m_types[id].create();
else
return null;
}
}
More information about the Digitalmars-d-learn
mailing list