Re: [Vala] C# developer, newbie question



Thanks, but same result, does it work that way at all?

GLib-GObject-CRITICAL **: 23:22:53.584: g_enum_get_value_by_name: assertion 'G_IS_ENUM_CLASS (enum_class)' failed

EnumClass enumc = (EnumClass)typeof(Gdk.WindowState).class_ref ();
var state = (Gdk.WindowState)enumc.get_value_by_name("FOCUSED").value;


I think it is better and easier to use int and string instead of enum

var val = ((int)get_window().get_state()).to_string();
.....
var state = (Gdk.WindowState)int.parse(val);


Am 19.12.18 um 22:51 schrieb Andy Lees:
I believe it's because the string produced in your first assignment to strState is the C transformed enum value which concatenates the type and value with an "_".  It does this to map the nested name space of Vala enums into the flat C name space.  You would need to remove the type + "_" from the returned string to create the associated enum value.

On Wed, Dec 19, 2018 at 10:28 PM Wolfgang Mauer <wolfgang mauer kabelmail de <mailto:wolfgang mauer kabelmail de>> wrote:

    Hi all,
    i try to put a enum to string and back, with no success.

    var strState = get_window().get_state().to_string(); <--
    "GDK_WINDOW_STATE_FOCUSED"

    and back dont work

    EnumClass enumc = (EnumClass)typeof(Gdk.WindowState).class_ref ();
    var state = (Gdk.WindowState)enumc.get_value_by_name(strState).value;

    What im doing wrong?

    Thanks for help

    Wolfgang


    _______________________________________________
    vala-list mailing list
    vala-list gnome org <mailto:vala-list gnome org>
    https://mail.gnome.org/mailman/listinfo/vala-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]