Re: Reflection/Introspection?

2013-10-17 Thread Jacob Carlborg

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


Reflection/Introspection?

2013-10-16 Thread DDD

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?


Re: Reflection/Introspection?

2013-10-16 Thread Craig Dillabaugh

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


Re: Reflection/Introspection?

2013-10-16 Thread Craig Dillabaugh

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:

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


Vibe source code for deserializeJson can be viewed at:

https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/data/json.d



Re: Reflection/Introspection?

2013-10-16 Thread Manu
On 17 October 2013 11:47, DDD dcb854d0b...@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.