// **************************************************************** // This is free software licensed under the NUnit license. You // may obtain a copy of the license as well as information regarding // copyright ownership at http://nunit.org/?p=license&r=2.4. // **************************************************************** using System; using System.Reflection; namespace NUnit.Core { /// /// Enumeration identifying a common language /// runtime implementation. /// public enum RuntimeType { /// Microsoft .NET Framework Net, /// Microsoft .NET Compact Framework NetCF, /// Microsoft Shared Source CLI SSCLI, /// Mono Mono } /// /// RuntimeFramework represents a particular version /// of a common language runtime implementation. /// public sealed class RuntimeFramework { private RuntimeType runtime; private Version version; /// /// Constructor /// /// The runtime type of the framework /// The version of the framework public RuntimeFramework( RuntimeType runtime, Version version ) { this.runtime = runtime; this.version = version; } /// /// Static method to return a RuntimeFramework object /// for the frameowrk that is currently in use. /// public static RuntimeFramework CurrentFramework { get { RuntimeType runtime = Type.GetType( "Mono.Runtime", false ) != null ? RuntimeType.Mono : RuntimeType.Net; return new RuntimeFramework( runtime, Environment.Version ); } } /// /// The type of this runtime framework /// public RuntimeType Runtime { get { return runtime; } } /// /// The version of this runtime framework /// public Version Version { get { return version; } } /// /// Gets a display string for the particular framework version /// /// A string used to display the framework in use public string GetDisplayName() { if ( runtime == RuntimeType.Mono ) { Type monoRuntimeType = Type.GetType( "Mono.Runtime", false ); MethodInfo getDisplayNameMethod = monoRuntimeType.GetMethod( "GetDisplayName", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding ); if ( getDisplayNameMethod != null ) return (string)getDisplayNameMethod.Invoke( null, new object[0] ); } return runtime.ToString() + " " + Version.ToString(); } } }