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