mail-archives/mono-list/2003-October/016668.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 == &quot;\n&quot;)
return RunningOS.Unix;
else
return RunningOS.Windows;
}
}
public static RunningCLI CLI {
get {
Type enumType = typeof(PlatformID);
if (Enum.IsDefined (enumType, &quot;Unix&quot;)) // check if it is Mono
return RunningCLI.Mono;
if (System.Environment.NewLine == &quot;\n&quot;) // is it correct on Rotor and
DotGnu?
return RunningCLI.Alternative;
return RunningCLI.DotNet;
}
}
public static void Main(String[] parameters) {
Console.WriteLine(&quot;Running in {0} within the {1} CLI&quot;, 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>
&gt;<i>From: Fergus Henderson &lt;<A HREF="mailto:fjh@cs.mu.OZ.AU">fjh@cs.mu.OZ.AU</A>&gt;
</I>&gt;<i>To: A Rafael D Teixeira &lt;<A HREF="mailto:rafaelteixeirabr@hotmail.com">rafaelteixeirabr@hotmail.com</A>&gt;
</I>&gt;<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>&gt;<i><A HREF="mailto:mono-br@redesolbrasil.org">mono-br@redesolbrasil.org</A>
</I>&gt;<i>Subject: Re: [Mono-list] Determining the platform at compile and run time
</I>&gt;<i>Date: Fri, 31 Oct 2003 12:31:43 +1100
</I>&gt;<i>
</I>&gt;<i>On 30-Oct-2003, A Rafael D Teixeira &lt;<A HREF="mailto:rafaelteixeirabr@hotmail.com">rafaelteixeirabr@hotmail.com</A>&gt; wrote:
</I>&gt;<i> &gt; Here is a small twist, save it as Mono.Environment.cs and compile as a
</I>&gt;<i> &gt; library to use or as an executable to just test:
</I>&gt;<i> &gt;
</I>&gt;<i> &gt; -------
</I>&gt;<i> &gt; // How can I tell dynamically what platform my code is running on?
</I>&gt;<i> &gt; //
</I>&gt;<i> &gt; // This is one possible approach, contributed by Aleksey Demakov
</I>&gt;<i> &gt; (<A HREF="mailto:avd@openlinksw.com">avd@openlinksw.com</A>)
</I>&gt;<i> &gt; // And encapsulated by Rafael Teixeira (<A HREF="mailto:rafaelteixeirabr@hotmail.com">rafaelteixeirabr@hotmail.com</A>)
</I>&gt;<i>
</I>&gt;<i>That code does the wrong thing when running under Rotor or DotGNU.
</I>&gt;<i>
</I>&gt;<i>--
</I>&gt;<i>Fergus Henderson &lt;<A HREF="mailto:fjh@cs.mu.oz.au">fjh@cs.mu.oz.au</A>&gt; | &quot;I have always known that the
</I>&gt;<i>pursuit
</I>&gt;<i>The University of Melbourne | of excellence is a lethal habit&quot;
</I>&gt;<i>WWW: &lt;<A HREF="http://www.cs.mu.oz.au/~fjh">http://www.cs.mu.oz.au/~fjh</A>&gt; | -- 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>