static IntPtr New (string name, string nick, string blurb, ParamFlags flags) { if (name == null) { throw new ArgumentNullException (nameof (name)); } if (nick == null) { throw new ArgumentNullException (nameof (nick)); } if (blurb == null) { throw new ArgumentNullException (nameof (blurb)); } var namePtr = GMarshal.StringToUtf8Ptr (name); var nickPtr = GMarshal.StringToUtf8Ptr (nick); var blurbPtr = GMarshal.StringToUtf8Ptr (blurb); var ret = g_param_spec_pointer (namePtr, nickPtr, blurbPtr, flags); // Any strings that have the cooresponding static flag set must not // be freed because they are passed to g_intern_static_string(). if (!flags.HasFlag (ParamFlags.StaticName)) { GMarshal.Free (namePtr); } if (!flags.HasFlag (ParamFlags.StaticNick)) { GMarshal.Free (nickPtr); } if (!flags.HasFlag (ParamFlags.StaticBlurb)) { GMarshal.Free (blurbPtr); } return ret; }
static IntPtr New(string name, string nick, string blurb, VariantType type, Variant defaultValue, ParamFlags flags) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (nick == null) { throw new ArgumentNullException(nameof(nick)); } if (blurb == null) { throw new ArgumentNullException(nameof(blurb)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } if (defaultValue != null && !defaultValue.IsOfType(type)) { throw new ArgumentException("default value does not match type", nameof(defaultValue)); } var namePtr = GMarshal.StringToUtf8Ptr(name); var nickPtr = GMarshal.StringToUtf8Ptr(nick); var blurbPtr = GMarshal.StringToUtf8Ptr(blurb); var defaultValuePtr = defaultValue?.Handle ?? IntPtr.Zero; var ret = g_param_spec_variant(namePtr, nickPtr, blurbPtr, type.Handle, defaultValuePtr, flags); GC.KeepAlive(type); GC.KeepAlive(defaultValue); // Any strings that have the cooresponding static flag set must not // be freed because they are passed to g_intern_static_string(). if (!flags.HasFlag(ParamFlags.StaticName)) { GMarshal.Free(namePtr); } if (!flags.HasFlag(ParamFlags.StaticNick)) { GMarshal.Free(nickPtr); } if (!flags.HasFlag(ParamFlags.StaticBlurb)) { GMarshal.Free(blurbPtr); } return(ret); }
static IntPtr New(string name, string nick, string blurb, GType flagsType, int defaultValue, ParamFlags flags) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (nick == null) { throw new ArgumentNullException(nameof(nick)); } if (blurb == null) { throw new ArgumentNullException(nameof(blurb)); } if (!flagsType.IsA(GType.Flags)) { throw new ArgumentException("Expecting an enum type", nameof(flagsType)); } var namePtr = GMarshal.StringToUtf8Ptr(name); var nickPtr = GMarshal.StringToUtf8Ptr(nick); var blurbPtr = GMarshal.StringToUtf8Ptr(blurb); var ret = g_param_spec_flags(namePtr, nickPtr, blurbPtr, flagsType, defaultValue, flags); // Any strings that have the cooresponding static flag set must not // be freed because they are passed to g_intern_static_string(). if (!flags.HasFlag(ParamFlags.StaticName)) { GMarshal.Free(namePtr); } if (!flags.HasFlag(ParamFlags.StaticNick)) { GMarshal.Free(nickPtr); } if (!flags.HasFlag(ParamFlags.StaticBlurb)) { GMarshal.Free(blurbPtr); } return(ret); }
static IntPtr New(string name, string nick, string blurb, ParamSpec elementSpec, ParamFlags flags) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (nick == null) { throw new ArgumentNullException(nameof(nick)); } if (blurb == null) { throw new ArgumentNullException(nameof(blurb)); } var namePtr = GMarshal.StringToUtf8Ptr(name); var nickPtr = GMarshal.StringToUtf8Ptr(nick); var blurbPtr = GMarshal.StringToUtf8Ptr(blurb); var elementSpecPtr = elementSpec?.Handle ?? IntPtr.Zero; var ret = g_param_spec_value_array(namePtr, nickPtr, blurbPtr, elementSpecPtr, flags); GC.KeepAlive(elementSpec); // Any strings that have the cooresponding static flag set must not // be freed because they are passed to g_intern_static_string(). if (!flags.HasFlag(ParamFlags.StaticName)) { GMarshal.Free(namePtr); } if (!flags.HasFlag(ParamFlags.StaticNick)) { GMarshal.Free(nickPtr); } if (!flags.HasFlag(ParamFlags.StaticBlurb)) { GMarshal.Free(blurbPtr); } return(ret); }