Re: learning reflection in D

2017-10-05 Thread drug via Digitalmars-d-learn
05.10.2017 18:04, Adam D. Ruppe пишет: On Thursday, 5 October 2017 at 14:59:10 UTC, drug wrote: 1) why .stringof and typeid() is equal logically and different in fact? What is difference between them? Is it that stringof compile time and typeid runtime things? Anyway wouldn't it be better they

Re: learning reflection in D

2017-10-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 October 2017 at 14:59:10 UTC, drug wrote: 1) why .stringof and typeid() is equal logically and different in fact? What is difference between them? Is it that stringof compile time and typeid runtime things? Anyway wouldn't it be better they will equal both logically and literally

learning reflection in D

2017-10-05 Thread drug via Digitalmars-d-learn
https://run.dlang.io/is/8LbmzG 1) why .stringof and typeid() is equal logically and different in fact? What is difference between them? Is it that stringof compile time and typeid runtime things? Anyway wouldn't it be better they will equal both logically and literally? 2) Where do these attri

Re: Reflection in D

2017-01-28 Thread medhi558 via Digitalmars-d-learn
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()

Re: Reflection in D

2017-01-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 28 January 2017 at 07:10:27 UTC, medhi558 wrote: I have a last question, currently i use : if(lc.name.indexOf("protocol.messages") != -1) If they're all in the same module, you can also use the compile time reflection to scan the module for classes. That's foreach(memberName; __

Re: Reflection in D

2017-01-28 Thread medhi558 via Digitalmars-d-learn
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

Re: Reflection in D

2017-01-28 Thread medhi558 via Digitalmars-d-learn
abstract class NetworkMessage { uint MessageId; // } override class QueueStatusUpdateMessage : NetworkMessage { uint MessageId = 1; // } override class Message2 : NetworkMessage { uint MessageId = 2; // } override class Message3 : NetworkMessage { uint Me

Re: Reflection in D

2017-01-28 Thread rumbu via Digitalmars-d-learn
On Saturday, 28 January 2017 at 07:03:51 UTC, medhi558 wrote: public static NetworkMessage GetInstance(string id) { auto v = (id in ProtocolMessageManager.m_types); if (v !is null) return cast(NetworkMessage)ProtocolMessageManager.m_types[id].create(); else

Re: Reflection in D

2017-01-28 Thread rumbu via Digitalmars-d-learn
On Saturday, 28 January 2017 at 08:18:15 UTC, medhi558 wrote: On Saturday, 28 January 2017 at 07:39:51 UTC, rumbu wrote: On Saturday, 28 January 2017 at 07:10:27 UTC, medhi558 wrote: I have a last question, currently i use : if(lc.name.indexOf("protocol.messages") != -1) To know if the class i

Re: Reflection in D

2017-01-28 Thread medhi558 via Digitalmars-d-learn
On Saturday, 28 January 2017 at 07:39:51 UTC, rumbu wrote: On Saturday, 28 January 2017 at 07:10:27 UTC, medhi558 wrote: I have a last question, currently i use : if(lc.name.indexOf("protocol.messages") != -1) To know if the class is a NetworkMessage, Would be possible to do this if(lc is Ne

Re: Reflection in D

2017-01-27 Thread rumbu via Digitalmars-d-learn
On Saturday, 28 January 2017 at 07:10:27 UTC, medhi558 wrote: I have a last question, currently i use : if(lc.name.indexOf("protocol.messages") != -1) To know if the class is a NetworkMessage, Would be possible to do this if(lc is NetworkMessage) Sorry for my English, i speak french. if (

Re: Reflection in D

2017-01-27 Thread medhi558 via Digitalmars-d-learn
I have a last question, currently i use : if(lc.name.indexOf("protocol.messages") != -1) To know if the class is a NetworkMessage, Would be possible to do this if(lc is NetworkMessage) Sorry for my English, i speak french.

Re: Reflection in D

2017-01-27 Thread medhi558 via Digitalmars-d-learn
I develop a game server. Currently I use a switch : import protocol.messages.connection.Message1; import protocol.messages.connection.Message2; import protocol.messages.queues.Message3; import .. import protocol.messages.NetworkMessage; class ProtocolMessageManager { public static N

Re: Reflection in D

2017-01-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 27 January 2017 at 21:02:13 UTC, medhi558 wrote: Hello, I would like to know if it is possible to recover all classes in the project in D. Yes, `foreach(mod; ModuleInfo) foreach(lc; mod.localClasses)`... but why do you want it? That facility is kinda limited in doing many things wi

Reflection in D

2017-01-27 Thread medhi558 via Digitalmars-d-learn
Hello, I would like to know if it is possible to recover all classes in the project in D. Example in c# : Assembly asm = Assembly.GetAssembly(typeof(MyClass)); foreach (Type type in asm.GetTypes()) { }