[Mono-list] System.PlatformID Issues

Piers Haken piersh@friskit.com
Wed, 10 Jul 2002 12:59:16 -0700


WARNING: this is a hack ;-)

if (System.Environment.OSVersion.Platform.ToString () == "Unix")
{
}

Piers.

-----Original Message-----
From: Oren Novotny [mailto:osn@po.cwru.edu] 
Sent: Wednesday, July 10, 2002 10:03 AM
To: mono-list@ximian.com
Subject: [Mono-list] System.PlatformID Issues


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
}
else
{
	// 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
check PlatformID.Unix.  

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...


--Oren




_______________________________________________
Mono-list maillist  -  Mono-list@ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list