[Mono-list] Determining the platform at compile and run time

Richard Torkar richard.torkar@htu.se
Thu, 30 Oct 2003 09:39:50 +0100

On Thu, 2003-10-30 at 10:41, Jonathan Gilbert wrote:
> At 09:46 AM 29/10/2003 -0800, Jackson Harper jackson-at-ximian.com
> |mono-list subscription| wrote:
> >On Wed, 2003-10-29 at 09:33, Chris Seaton wrote:
> >> How do I know what OS my program is running on at run time? PlatformID
> >> contains no entry for any systems apart from Windows.
> >
> >http://www.nullenvoid.com/mono/wiki/index.php/DeveloperFaq?PHPSESSID=3De=
> 73fcad70a585f9bf5bb57ba841
> This URL does not work for me in Internet Explorer:

Strange, it works for me. Anyway I think this is what Jackson wanted you
to see:

How can I tell dynamically what platform my code is running on?

This is one possible approach, contributed by Aleksey Demakov

  Type enumType =3D typeof (PlatformID);
  if (Enum.IsDefined (enumType, "Unix"))
    if (~Environment.OSVersion.Platform =3D=3D (PlatformID) Enum.Parse (enu=
mType, "Unix"))
      Console.WriteLine ("Platform: Mono on Unix");
      Console.WriteLine ("Platform: Mono on Win32");
  } else
    Console.WriteLine ("Platform: .NET");

Dept. of Informatics and Mathematics
University of Trollh=E4ttan/Uddevalla
P.O. Box 957, SE-461 29 Trollh=E4ttan