[Gtk-sharp-list] using alias directive... in use with GLib Basic Types

Charles Iliya Krempeaux charles@reptile.ca
26 Feb 2003 23:09:51 -0800


Hello,

I just wanted to bring to everyone's attention the 
"using-alias-directive" that is part of C#.  It can
be used as a kind of "typedef".

(Although, as I understand it, it is NOT something you can
declare in one place, and then import into other places.)

To use it you would do something like:

    namespace A {
    namespace B {
        class C {}
    }
    }


    namespace X {
        using Y = A.B.C;

        class Z : Y {}
    }


The important thing in the above example is that I was
able to say "Y" instead of saying "A.B.C".

Now, this same technique can be used when wrapping libraries.

When we do DLLImport's, our procedure declarations often have
convoluted declarations that have signatures that look very
different from their C header counter parts.

For example, with the way we are doing it currently, we
might have:

  [System.Runtime.InteropServices.DllImport("gnomevfs-2")]
  static extern GnomeVFSResult gnome_vfs_read(
      System.IntPtr handle
    , System.IntPtr buffer
    , System.Int64  bytes
    , System.IntPtr bytes_read
    );

But, if we use a "using-alias-directive", then we would have
something like:

  using GnomeVFSFileSize     = System.Int64;
  using GnomeVFSFileSizePtr  = System.IntPtr;
  using GnomeVFSHandlePtr    = System.IntPtr;
  using GnomeVFSResult	     = System.Int32;
  using gconstpointer	     = System.IntPtr;
  using gpointer             = System.IntPtr;
            
  // ...


  [System.Runtime.InteropServices.DllImport("gnomevfs-2")]
  static extern GnomeVFSResult gnome_vfs_read(
      GnomeVFSHandlePtr   handle
    , gpointer            buffer
    , GnomeVFSFileSize    bytes
    , GnomeVFSFileSizePtr bytes_read
    );


Perhaps the generated .cs files, that gapi/gapi_codegen create
should use this technique.

Also, maybe it should be a "standard" we set for ourself to
use this technique throughout the Gtk# source code.

What does everyone else think??


See ya

-- 
     Charles Iliya Krempeaux, BSc
     charles@reptile.ca

________________________________________________________________________
 Reptile Consulting & Services    604-REPTILE    http://www.reptile.ca/