зеркало из https://github.com/mono/mail-archives.git
160 строки
6.0 KiB
HTML
160 строки
6.0 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||
<HTML>
|
||
<HEAD>
|
||
<TITLE> [Mono-list] Determining the platform at compile and run time
|
||
</TITLE>
|
||
<LINK REL="Index" HREF="index.html" >
|
||
<LINK REL="made" HREF="mailto:rafaelteixeirabr%40hotmail.com">
|
||
<META NAME="robots" CONTENT="index,nofollow">
|
||
|
||
<LINK REL="Previous" HREF="016679.html">
|
||
<LINK REL="Next" HREF="016669.html">
|
||
</HEAD>
|
||
<BODY BGCOLOR="#ffffff">
|
||
<H1>[Mono-list] Determining the platform at compile and run time
|
||
</H1>
|
||
<B>A Rafael D Teixeira
|
||
</B>
|
||
<A HREF="mailto:rafaelteixeirabr%40hotmail.com"
|
||
TITLE="[Mono-list] Determining the platform at compile and run time">rafaelteixeirabr@hotmail.com
|
||
</A><BR>
|
||
<I>Fri, 31 Oct 2003 02:02:04 -0200</I>
|
||
<P><UL>
|
||
<LI> Previous message: <A HREF="016679.html">[Mono-list] Determining the platform at compile and run time
|
||
</A></li>
|
||
<LI> Next message: <A HREF="016669.html">[Mono-list] mod_mono installation error
|
||
</A></li>
|
||
<LI> <B>Messages sorted by:</B>
|
||
<a href="date.html#16668">[ date ]</a>
|
||
<a href="thread.html#16668">[ thread ]</a>
|
||
<a href="subject.html#16668">[ subject ]</a>
|
||
<a href="author.html#16668">[ author ]</a>
|
||
</LI>
|
||
</UL>
|
||
<HR>
|
||
<!--beginarticle-->
|
||
<PRE>Well, if you could elaborate on what happens with this code when running
|
||
within those alternative implementations, we can try to make it work better
|
||
with these two.
|
||
|
||
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
|
||
(<A HREF="mailto:avd@openlinksw.com">avd@openlinksw.com</A>)
|
||
// And tweaked/encapsulated by Rafael Teixeira
|
||
(<A HREF="mailto:rafaelteixeirabr@hotmail.com">rafaelteixeirabr@hotmail.com</A>)
|
||
|
||
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
|
||
|
||
---------------
|
||
[<A HREF="mailto:rafael@redhat9">rafael@redhat9</A> 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: <A HREF="http://monoblog.blogspot.com/">http://monoblog.blogspot.com/</A>
|
||
Brazilian Portuguese Blog: <A HREF="http://monoblog.weblogger.terra.com.br/">http://monoblog.weblogger.terra.com.br/</A>
|
||
|
||
><i>From: Fergus Henderson <<A HREF="mailto:fjh@cs.mu.OZ.AU">fjh@cs.mu.OZ.AU</A>>
|
||
</I>><i>To: A Rafael D Teixeira <<A HREF="mailto:rafaelteixeirabr@hotmail.com">rafaelteixeirabr@hotmail.com</A>>
|
||
</I>><i>CC: <A HREF="mailto:richard.torkar@htu.se">richard.torkar@htu.se</A>, <A HREF="mailto:mono-list@lists.ximian.com">mono-list@lists.ximian.com</A>,
|
||
</I>><i><A HREF="mailto:mono-br@redesolbrasil.org">mono-br@redesolbrasil.org</A>
|
||
</I>><i>Subject: Re: [Mono-list] Determining the platform at compile and run time
|
||
</I>><i>Date: Fri, 31 Oct 2003 12:31:43 +1100
|
||
</I>><i>
|
||
</I>><i>On 30-Oct-2003, A Rafael D Teixeira <<A HREF="mailto:rafaelteixeirabr@hotmail.com">rafaelteixeirabr@hotmail.com</A>> wrote:
|
||
</I>><i> > Here is a small twist, save it as Mono.Environment.cs and compile as a
|
||
</I>><i> > library to use or as an executable to just test:
|
||
</I>><i> >
|
||
</I>><i> > -------
|
||
</I>><i> > // How can I tell dynamically what platform my code is running on?
|
||
</I>><i> > //
|
||
</I>><i> > // This is one possible approach, contributed by Aleksey Demakov
|
||
</I>><i> > (<A HREF="mailto:avd@openlinksw.com">avd@openlinksw.com</A>)
|
||
</I>><i> > // And encapsulated by Rafael Teixeira (<A HREF="mailto:rafaelteixeirabr@hotmail.com">rafaelteixeirabr@hotmail.com</A>)
|
||
</I>><i>
|
||
</I>><i>That code does the wrong thing when running under Rotor or DotGNU.
|
||
</I>><i>
|
||
</I>><i>--
|
||
</I>><i>Fergus Henderson <<A HREF="mailto:fjh@cs.mu.oz.au">fjh@cs.mu.oz.au</A>> | "I have always known that the
|
||
</I>><i>pursuit
|
||
</I>><i>The University of Melbourne | of excellence is a lethal habit"
|
||
</I>><i>WWW: <<A HREF="http://www.cs.mu.oz.au/~fjh">http://www.cs.mu.oz.au/~fjh</A>> | -- the last words of T. S. Garp.
|
||
</I>
|
||
_________________________________________________________________
|
||
MSN Messenger: instale gr<67>tis e converse com seus amigos.
|
||
<A HREF="http://messenger.msn.com.br">http://messenger.msn.com.br</A>
|
||
|
||
|
||
</PRE>
|
||
<!--endarticle-->
|
||
<HR>
|
||
<P><UL>
|
||
<!--threads-->
|
||
<LI> Previous message: <A HREF="016679.html">[Mono-list] Determining the platform at compile and run time
|
||
</A></li>
|
||
<LI> Next message: <A HREF="016669.html">[Mono-list] mod_mono installation error
|
||
</A></li>
|
||
<LI> <B>Messages sorted by:</B>
|
||
<a href="date.html#16668">[ date ]</a>
|
||
<a href="thread.html#16668">[ thread ]</a>
|
||
<a href="subject.html#16668">[ subject ]</a>
|
||
<a href="author.html#16668">[ author ]</a>
|
||
</LI>
|
||
</UL>
|
||
</body></html>
|