I dont know how to do it with object investigation at run time, as you'd
with python, i. e. But your problem is just a form of serialization that
you can achieve with a interface or a base class subclassing all of your
seriable object.
On Sun, Apr 10, 2016 at 14:13 Baptiste Gelez <gelezbapti...@openmailbox.org>
wrote:

> Actually, I have got a method named create_model that have an Object
> named obj as parameter. I want to get all the properties of this object
> and store their values in the HashMap result.
> For example, let's imagine I have got this class :
>
> public class MyClass : Object {
>
>      public string prop1 {get; set; default = "hello";}
>
>      public ArrayList<string> prop2 {get; set;}
>
>      public MyClass () {
>          this.prop2 = new ArrayList<string> ();
>          this.prop2.add ("hey");
>          this.prop2.add ("test");
>      }
>
> }
>
> Then, I would like to have an HashMap<string, string> that look like
> this :
>
> "prop1" -> "hello"
> "prop2[0] -> "hey"
> "prop2[0] -> "test"
>
> just by using this code :
>
> var obj = new MyClass ();
> create_model (obj);
>
> With the code I shown you, I can use create_model on object that have
> properties of basic types like string, int, etc.
> But I wonder how to do this with a Gee.Collection : I know how to
> enumerate it and get the type which is stored in this collection, but
> I wonder how to instantiate a object of the same type as this which is
> stored in the collection, to assign the object I at a given index of the
> collection, and
> then to get all those properties, and store them in my HashMap<string,
> string>.
>
> I hope this time you understand what I mean.
>
> Le 2016-04-10 16:35, Felipe Lavratti a écrit :
> > Sorry, its not clear to me.
> > Where is the reflection? You will have the Type name of an Object in
> > your HasMap, then you will want to create an instance with this name?
> >
> > On Sun, Apr 10, 2016 at 04:32 Baptiste Gelez
> > <gelezbapti...@openmailbox.org> wrote:
> >
> >> Le 2016-04-09 20:46, Daniel Espinosa a écrit :
> >>> May you can use HashMap<string,Value?>()
> >>>
> >>> Value? Makes boxed any value supported by GLib.Value, almost any
> >>> value, from basic like int to GLib.Object, any any struct if it
> >> is
> >>> properly boxed.
> >>>
> >>> El abr. 9, 2016 12:11 PM, "Baptiste Gelez"
> >>> <gelezbapti...@openmailbox.org> escribió:
> >>>
> >>>> Hello everyone !
> >>>>
> >>>> I would like to retrieve any property of an object. I presently
> >> use
> >>>> this
> >>>> code :
> >>>>
> >>>> HashMap<string, string> result = new HashMap<string, string> ();
> >>>>
> >>>> foreach (ParamSpec spec in obj.get_class ().list_properties ())
> >> {
> >>>> GLib.Value val = GLib.Value (typeof (string));
> >>>> obj.get_property (spec.get_nick (), ref val);
> >>>> result [spec.get_nick ()] = (string) val;
> >>>> }
> >>>>
> >>>> return result;
> >>>>
> >>>> There is no problem when I'm getting "simple" values like int,
> >>>> string,
> >>>> double, etc ... But I would like to be able to get all the
> >> elements
> >>>> of
> >>>> Gee.Collection. Have you got any idea of how to do that ?
> >>>>
> >>>> Thanks ! (And excuse me for possible English mistakes)
> >>>>
> >>>> _______________________________________________
> >>>> vala-list mailing list
> >>>> vala-list@gnome.org
> >>>> https://mail.gnome.org/mailman/listinfo/vala-list [1] [1]
> >>>
> >>>
> >>> Links:
> >>> ------
> >>> [1] https://mail.gnome.org/mailman/listinfo/vala-list [1]
> >>
> >> I'm not sure that you well understand my question. I probably
> >> poorly
> >> explained.
> >>
> >> I'm building a library that'll be able to transform any object into
> >> an
> >> HashMap<string, string> associating the name of the property with
> >> its
> >> value as a string.
> >> In the code I presently have, I can do this with basic types like
> >> int,
> >> string, etc. But I would like to get all the elements of a
> >> Gee.Collection. I can do this by using it's iterator property, but
> >> even
> >> if I know how to enumerate them and how to get their type, I don't
> >> know
> >> how to dynamically create a new instance of this type and convert
> >> en
> >> element of the collection (which I have as an Object) to this type.
> >> I
> >> hope it's clearer now.
> >> _______________________________________________
> >> vala-list mailing list
> >> vala-list@gnome.org
> >> https://mail.gnome.org/mailman/listinfo/vala-list [1]
> >
> >
> > Links:
> > ------
> > [1] https://mail.gnome.org/mailman/listinfo/vala-list
>
>
_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to