[Gtk-sharp-list] Gapi2 question
Andrew Pendleton
lists at andrewpendleton.net
Wed May 21 20:40:29 EDT 2008
I'm working on bindings for a gobject-based library that has a bunch of classes with constructors of the form:
some_library_object_new(gdouble param1, gdouble param2, ...) {
/* whatever */
}
where param1 and param2 are required parameters, and the ellipsis is to be replaced by the caller with an arbitrary number of key/value pairs to be used to fill in other, optional properties of the object, followed by a null (they use g_object_set_valist). Obviously, C# doesn't support methods of this kind, and since all of the properties that can be specified from the constructor are also accessible as properties that can be set later, I'm content to just leave the arguments after the required ones out of the bindings.
So, I need the bound constructor to come out as follows:
[DllImport("some_library.dll")]
static extern IntPtr some_library_asdf_new(double param1, double param2, IntPtr terminator);
public Asdf (double param1, double param2) : base (IntPtr.Zero)
{
if (GetType () != typeof (Asdf)) {
throw new InvalidOperationException ("Can't override this constructor.");
}
Raw = some_library_asdf_new(param1, param2, IntPtr.Zero);
}
that is to say, the wrapped C function needs to have an extra parameter, and rather than being exposed via the C# method, a null value always needs to be passed into the C function from the wrapping constructor.
So, my question: this occurs in a whole bunch of classes in the library. I know I can use the gapi2 fixer program to strip the constructors out of all of these classes, and use .custom files to hand-code new constructors for each one, but I'd rather not. Is there some way I can make gapi2 generate code with this behavior?
Andrew
More information about the Gtk-sharp-list
mailing list