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

Jonathan Pryor jonpryor@vt.edu
Fri, 31 Oct 2003 07:07:03 -0500


Just to continue Fergus' line of reasoning, Type Reflector (CVS module:
type-reflector) does the same thing.  It has three different front-ends
(Gtk#, System.Windows.Forms, and Console), that you can select by using
either a command-line argument (--displayer=NAME) or by setting an
option on the type-reflector.exe.config file.

Actually, the .config file supports an ordering of preferred front-ends,
so that it will try each one, in order, until it finds one that works.

 - Jon

On Thu, 2003-10-30 at 22:44, Fergus Henderson wrote:
> 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.