1 // ****************************************************************
\r
2 // This is free software licensed under the NUnit license. You
\r
3 // may obtain a copy of the license as well as information regarding
\r
4 // copyright ownership at http://nunit.org/?p=license&r=2.4.
\r
5 // ****************************************************************
\r
8 using System.Reflection;
\r
10 namespace NUnit.Core
\r
13 /// Enumeration identifying a common language
\r
14 /// runtime implementation.
\r
16 public enum RuntimeType
\r
18 /// <summary>Microsoft .NET Framework</summary>
\r
20 /// <summary>Microsoft .NET Compact Framework</summary>
\r
22 /// <summary>Microsoft Shared Source CLI</summary>
\r
24 /// <summary>Mono</summary>
\r
29 /// RuntimeFramework represents a particular version
\r
30 /// of a common language runtime implementation.
\r
32 public sealed class RuntimeFramework
\r
34 private RuntimeType runtime;
\r
35 private Version version;
\r
40 /// <param name="runtime">The runtime type of the framework</param>
\r
41 /// <param name="version">The version of the framework</param>
\r
42 public RuntimeFramework( RuntimeType runtime, Version version )
\r
44 this.runtime = runtime;
\r
45 this.version = version;
\r
49 /// Static method to return a RuntimeFramework object
\r
50 /// for the frameowrk that is currently in use.
\r
52 public static RuntimeFramework CurrentFramework
\r
56 RuntimeType runtime = Type.GetType( "Mono.Runtime", false ) != null
\r
57 ? RuntimeType.Mono : RuntimeType.Net;
\r
59 return new RuntimeFramework( runtime, Environment.Version );
\r
64 /// The type of this runtime framework
\r
66 public RuntimeType Runtime
\r
68 get { return runtime; }
\r
72 /// The version of this runtime framework
\r
74 public Version Version
\r
76 get { return version; }
\r
80 /// Gets a display string for the particular framework version
\r
82 /// <returns>A string used to display the framework in use</returns>
\r
83 public string GetDisplayName()
\r
85 if ( runtime == RuntimeType.Mono )
\r
87 Type monoRuntimeType = Type.GetType( "Mono.Runtime", false );
\r
88 MethodInfo getDisplayNameMethod = monoRuntimeType.GetMethod(
\r
89 "GetDisplayName", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding );
\r
90 if ( getDisplayNameMethod != null )
\r
91 return (string)getDisplayNameMethod.Invoke( null, new object[0] );
\r
94 return runtime.ToString() + " " + Version.ToString();
\r