[Mono-list] System.PlatformID Issues
Wed, 10 Jul 2002 13:03:18 -0400
I've been following the progress of Mono for some time, and I have to
congratulate all of the developers. It's looking good so far :).
Right now I have a question/problem with portability routines though.
I'm in the middle of developing a WinFoms application which is *almost*
pure managed code. Two of the functions need to call native code, which
is platform-specific (a spell check library and a library to obtain the
currently playing mp3 from the window of a known player application).
I have created an interface that can be implemented by platform-specific
classes, so that it'd be theoretically possible to check the
System.Environment.OSVersion.PlatformID and determine which class
library to use (so that on windows, the user32.dll is P/Invoked and on
Unix/Linux an appropriate GTk function is called).
Here's the problem though. While Mono's System.PlatformID enumeration
adds "Unix", I can't actually use that enumeration if I expect to
compile with VS.Net, since MS's PlatformID does not contain that value.
The only workaround that I can think of, which is clumsy, is to do:
PlatformID pid = System.Environment.OSVersion.Platform;
if( pid == PlatformID.Win32NT || pid == PlatformID.Win32Windows )
// Windows calls here
// Unix calls here
Clearly this type of structure would work, since when running on Mono,
the type PlatformID would be Unix and the first part of the if statement
would be false, executing the code in the else statement. This type of
structure seems like a convoluted way though, than just being able to
Is this the best way to get this type of code working? That leads to
the side-effect of having the PlatformID.Unix enumeration: if people
write code that actually uses PlatformID.Unix, which would compile under
Mono, it still wouldn't run on MS's Framework, since that value is
non-existent from MS's enumeration. I'm actually not even sure what
kind of error/result would happen, since it's impossible to compile an
enumeration that uses an invalid type (presently).
How is Mono addressing the issue of extending MS's framework in this
way, since I've noticed that there are a few other additions. Programs
using those additions (to the system/corlib) will all have problems when
on MS's framework...