digitalmars.D - Reflection/Introspection?
- DDD (9/9) Oct 16 2013 Does D have any reflection/introspection?
- Craig Dillabaugh (18/27) Oct 16 2013 Check out Vibe.D
- Craig Dillabaugh (4/35) Oct 16 2013 Vibe source code for deserializeJson can be viewed at:
- Manu (2/11) Oct 16 2013 Yes, there is quite thorough reflection in D. Serialisers are plentiful.
- Jacob Carlborg (6/15) Oct 17 2013 If you need something more advanced you can try Orange:
Does D have any reflection/introspection? I'd like to do something like this class Contact { string first, last int number } contact = json_deserialized!Contact(json_string); Is something like that possible?
Oct 16 2013
On Thursday, 17 October 2013 at 01:47:41 UTC, DDD wrote:Does D have any reflection/introspection? I'd like to do something like this class Contact { string first, last int number } contact = json_deserialized!Contact(json_string); Is something like that possible?Check out Vibe.D http://vibed.org/api/vibe.data.json/deserializeJson This is exactly what you are looking for I believe. For example I have the following code which works: import vibe.d; struct Foo { string bar; int num; } void deserializeExample() { Json js = Json.emptyObject; js.bar = "Hello world!"; js.num = 42; Foo afoo = deserializeJson!Foo( js ); assert( afoo.bar == "Hello world!"); assert( afoo.num == 42 ); }
Oct 16 2013
On Thursday, 17 October 2013 at 02:03:28 UTC, Craig Dillabaugh wrote:On Thursday, 17 October 2013 at 01:47:41 UTC, DDD wrote:Vibe source code for deserializeJson can be viewed at: https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/data/json.dDoes D have any reflection/introspection? I'd like to do something like this class Contact { string first, last int number } contact = json_deserialized!Contact(json_string); Is something like that possible?Check out Vibe.D http://vibed.org/api/vibe.data.json/deserializeJson This is exactly what you are looking for I believe. For example I have the following code which works: import vibe.d; struct Foo { string bar; int num; } void deserializeExample() { Json js = Json.emptyObject; js.bar = "Hello world!"; js.num = 42; Foo afoo = deserializeJson!Foo( js ); assert( afoo.bar == "Hello world!"); assert( afoo.num == 42 ); }
Oct 16 2013
On 17 October 2013 11:47, DDD <dcb854d0bfb1 f98b7c56a69c.anonbox.net> wrote:Does D have any reflection/introspection? I'd like to do something like this class Contact { string first, last int number } contact = json_deserialized!Contact(**json_string); Is something like that possible?Yes, there is quite thorough reflection in D. Serialisers are plentiful.
Oct 16 2013
On 2013-10-17 03:47, DDD wrote:Does D have any reflection/introspection? I'd like to do something like this class Contact { string first, last int number } contact = json_deserialized!Contact(json_string); Is something like that possible?If you need something more advanced you can try Orange: https://github.com/jacob-carlborg/orange Soon (hopefully) to be integrated to Phobos as std.serialization. -- /Jacob Carlborg
Oct 17 2013