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

Fergus Henderson fjh@cs.mu.OZ.AU
Fri, 31 Oct 2003 14:44:59 +1100


On 31-Oct-2003, Chris Seaton <chris@chrisseaton.com> wrote:
> On Fri, 2003-10-31 at 01:29, Fergus Henderson wrote:
> > On 29-Oct-2003, Chris Seaton <chris@chrisseaton.com> wrote:
> > > How do I know what OS my program is running on at run time?
> > 
> > Why do you care?
> 
> To select between GTK# and SWF.

I can quite easily imagine systems on which both are supported.

I would suggest something like this:

	bool prefer_gtk;	// set by command-line option
				// or environment variable

	if (prefer_gtk)
		try {
			code to use GTK#;
		} catch (GTK# not availabe) {
			code to use SWF;
		}
	} else {
		try {
			code to use SWF;
		} catch (SWF not availabe) {
			code to use GTK#;
		}
	}

You can do this just for the first call, and save the results in a
variable which you then use to decide which GUI to use for later calls.

It would be reasonable to use the OS setting to determine the default
value of prefer_gtk.  But you should definitely try both, regardless of
which OS the platform claims to be.

-- 
From: Fergus Henderson <fjh@cs.mu.oz.au>
Fergus Henderson <fjh@cs.mu.oz.au>  |  "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.