But, out of curiosity, do you know why dotgnu doesn't use the extension of the PlatformID enumeration as Mono? Or does it?
To be totally fair, my own code inside Bamboo.Prevalence still checks the newline string, to guess the OS... so mixing both approaches, we have:
---------------
// How can I tell dynamically what platform my code is running on?
//
// This is one possible approach, contributed by Aleksey Demakov ([EMAIL PROTECTED])
// And tweaked/encapsulated by Rafael Teixeira ([EMAIL PROTECTED])
using System;
namespace Mono {
public enum RunningOS { Unix, Windows };
public enum RunningCLI { Mono, DotNet, Alternative };public class Environment {
public static RunningOS OS {
get {
if (System.Environment.NewLine == "\n")
return RunningOS.Unix;
else
return RunningOS.Windows;
}
} public static RunningCLI CLI {
get {
Type enumType = typeof(PlatformID);if (Enum.IsDefined (enumType, "Unix")) // check if it is Mono
return RunningCLI.Mono;
if (System.Environment.NewLine == "\n") // is it correct on Rotor and DotGnu?
return RunningCLI.Alternative;
return RunningCLI.DotNet;
}
}
public static void Main(String[] parameters) {
Console.WriteLine("Running in {0} within the {1} CLI", Environment.OS, Environment.CLI);
}
} } ---------------
that on RH9/Mono gives
--------------- [EMAIL PROTECTED] desktop]$ mono Mono.Environment.exe Running in Unix within the Mono CLI ---------------
Does this new code, fare better with those other CLIs?
Best regards,
Rafael Teixeira Brazilian Polymath Mono Hacker since 16 Jul 2001 MonoBrasil Founder English Blog: http://monoblog.blogspot.com/ Brazilian Portuguese Blog: http://monoblog.weblogger.terra.com.br/
From: Fergus Henderson <[EMAIL PROTECTED]>
To: A Rafael D Teixeira <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]
Subject: Re: [Mono-list] Determining the platform at compile and run time
Date: Fri, 31 Oct 2003 12:31:43 +1100
On 30-Oct-2003, A Rafael D Teixeira <[EMAIL PROTECTED]> wrote: > Here is a small twist, save it as Mono.Environment.cs and compile as a > library to use or as an executable to just test: > > ------- > // How can I tell dynamically what platform my code is running on? > // > // This is one possible approach, contributed by Aleksey Demakov > ([EMAIL PROTECTED]) > // And encapsulated by Rafael Teixeira ([EMAIL PROTECTED])
That code does the wrong thing when running under Rotor or DotGNU.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
_________________________________________________________________
MSN Messenger: instale gr�tis e converse com seus amigos. http://messenger.msn.com.br
_______________________________________________ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list
