Hi,

because you defined the "attributes" as fields (eg. private class instance
variable) and not a properties.

See https://wiki.gnome.org/Projects/Vala/Tutorial#Properties for more
details.

Try to change the Test class as:

public class Test : GLib.Object, Saveable {
        public string name { get; private set; }
        public int zahl { get; private set; }

        private List<string> liste;

        public bool boolean { get; set; }
        protected uint16 kleine;

        internal int32 integ;

        public Test (string name, int zahl, List<string> liste) {
                this.name = name;
                this.zahl = zahl;
                this.liste = liste.copy ();
        }
}

you should at least see the name, zahl and boolean properties listed when
calling the save_object function.

Ciao,
Andrea



On Mon, Mar 23, 2015 at 12:15 PM, Philipp Trommler <
keinerschreibtmir...@msn.com> wrote:

> Hi!
>
> This is my first post on this list so I just want to say hello to
> everybody. My name is Philipp Trommler, I'm from Dresden, Germany and
> I'm programming Vala as a hobby. I really like Vala as I like the
> syntax, the fact that it's performant and the good integration into the
> gnome ecosystem. In the last days I wanted to dig a bit deeper into
> serious Vala programming what leads me to my question:
>
> What are common ways to access an object's attributes? I checked and
> tried `GLib.ParamSpec` but receiving an empty array all the time. Is
> there any other method?
>
> The background is that I want to save an object's attributes into a
> file. Alternatively I would save the whole object (that's what I tried
> before, without luck, because I can't figure out how to access all of
> the object's parts in memory), but accessing the attributes would be
> enough for now.
>
> Maybe I'm just doing something wrong, so here's my code:
>
> ```
> public interface Saveable : GLib.Object {
>         public virtual void save_object (string filename) {
>                 unowned GLib.ObjectClass object_class = this.get_class ();
>                 GLib.File file = GLib.File.new_for_path (filename);
>                 GLib.FileOutputStream file_output_stream = file.create
> (GLib.FileCreateFlags.PRIVATE |
> GLib.FileCreateFlags.REPLACE_DESTINATION);
>                 foreach (GLib.ParamSpec param_spec in
> object_class.list_properties ())
> {
>                         stdout.printf ("%s\n", param_spec.get_name ());
>                 }
>         }
> }
>
> public class Test : GLib.Object, Saveable {
>         private string name;
>         private int zahl;
>         private List<string> liste;
>
>         public bool boolean;
>         protected uint16 kleine;
>
>         internal int32 integ;
>
>         public Test (string name, int zahl, List<string> liste) {
>                 this.name = name;
>                 this.zahl = zahl;
>                 this.liste = liste.copy ();
>         }
> }
> ```
>
> So, as you can see, the class `Test` has some attributes. Why can't I
> access any of them?
>
> Greetings,
> Philipp.
>
> _______________________________________________
> vala-list mailing list
> vala-list@gnome.org
> 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