Example #1
0
        /*	static GLib.Value ParseUnichar (string strval)
         *      {
         *              return new GLib.Value (strval.Length == 1 ? (uint)strval[0] : 0U);
         *      }*/

        static GLib.Value ParseProperty(ParamSpec pspec, Type propType, string strval)
        {
            IntPtr gtype;

            if (propType != null)
            {
                gtype = ((GLib.GType)propType).Val;
            }

/*
 *                      FIXME: ValueType is not supported right now
 *
 *                      else if (pspec != null)
 *                              gtype = pspec.ValueType;
 */
            else
            {
                throw new GladeException("Bad type");
            }

            GLib.TypeFundamentals typef = (GLib.TypeFundamentals)(int) g_type_fundamental(gtype);

            if (gtype == Gtk.Adjustment.GType.Val)
            {
                return(ParseAdjustment(strval));
            }
            else if (typef == GLib.TypeFundamentals.TypeEnum)
            {
                return(ParseEnum(gtype, strval));
            }
            else if (typef == GLib.TypeFundamentals.TypeFlags)
            {
                return(ParseFlags(gtype, strval));
            }
// FIXME: Enable when ParamSpec.IsUnichar is implemented.
//			else if (pspec != null && pspec.IsUnichar)
//				return ParseUnichar (strval);
            else
            {
                return(ParseBasicType(typef, strval));
            }
        }
Example #2
0
        static GLib.Value ParseBasicType(GLib.TypeFundamentals type, string strval)
        {
            switch (type)
            {
            case GLib.TypeFundamentals.TypeChar:
                return(new GLib.Value(SByte.Parse(strval)));

            case GLib.TypeFundamentals.TypeUChar:
                return(new GLib.Value(Byte.Parse(strval)));

            case GLib.TypeFundamentals.TypeBoolean:
                return(new GLib.Value(strval == "True"));

            case GLib.TypeFundamentals.TypeInt:
                return(new GLib.Value(Int32.Parse(strval)));

            case GLib.TypeFundamentals.TypeUInt:
                return(new GLib.Value(UInt32.Parse(strval)));

            case GLib.TypeFundamentals.TypeInt64:
                return(new GLib.Value(Int64.Parse(strval)));

            case GLib.TypeFundamentals.TypeUInt64:
                return(new GLib.Value(UInt64.Parse(strval)));

            case GLib.TypeFundamentals.TypeFloat:
                return(new GLib.Value(Single.Parse(strval, System.Globalization.CultureInfo.InvariantCulture)));

            case GLib.TypeFundamentals.TypeDouble:
                return(new GLib.Value(Double.Parse(strval, System.Globalization.CultureInfo.InvariantCulture)));

            case GLib.TypeFundamentals.TypeString:
                return(new GLib.Value(strval));

            default:
                throw new GladeException("Could not parse");
            }
        }