[Mono-list] Multiplatform DllImport?

Miguel de Icaza miguel@ximian.com
23 Nov 2001 19:22:04 -0500


> Instead of having a separate .cs file for every platform
> to import the definition using PInvoke, I introduced a private
> attribute called "DllImportMap".  e.g.
> 
> [DllImportMap("winsock.dll", "*-sunos-*", "libsocket.so")]
> [DllImportMap("winsock.dll", "std-shared-object", "libc.so")]
> class SocketOps
> {
>     [DllImport("winsock.dll")]
>     public int listen(int fd, int backlog);
> }

Oh!  This is a really sweet idea!

> So as not to introduce too much embrace and extend,
> I made the attribute "floating".  That is, it can be in
> any namespace.  This allows a "private" class to be
> put into the importing assembly called something like
> "MyNamespace.DllImportMapAttribute".  This will
> not pollute the global namespace, and so third party
> programmers will not come to rely upon it by accident.

This is nice, and also, it can always be just an internal attribute as
well.

Miguel.