Beispiel #1
0
        /// <summary>
        /// Get all values for a enum (GType).
        /// </summary>
        /// <param name="type">Type to return enum values for.</param>
        /// <returns>A list of values.</returns>
        public static List <string> ValuesForEnum(IntPtr type)
        {
            var typeClass = GType.ClassRef(type);
            var enumClass = typeClass.Dereference <GEnumClass>();

            var values = new List <string>((int)(enumClass.NValues - 1));

            var ptr = enumClass.Values;

            // -1 since we always have a "last" member
            for (var i = 0; i < enumClass.NValues - 1; i++)
            {
                var nick = ptr.Dereference <GEnumValue>().ValueNick;
                values.Add(nick);

                ptr += Marshal.SizeOf(typeof(GEnumValue));
            }

            return(values);
        }