2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / nunit24 / NUnitCore / interfaces / RuntimeFramework.cs
blob2920feb8dd45b09de65df1755fcf52e5cb14c7ec
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 // ****************************************************************
7 using System;
8 using System.Reflection;
10 namespace NUnit.Core
12 /// <summary>
13 /// Enumeration identifying a common language
14 /// runtime implementation.
15 /// </summary>
16 public enum RuntimeType
18 /// <summary>Microsoft .NET Framework</summary>
19 Net,
20 /// <summary>Microsoft .NET Compact Framework</summary>
21 NetCF,
22 /// <summary>Microsoft Shared Source CLI</summary>
23 SSCLI,
24 /// <summary>Mono</summary>
25 Mono
28 /// <summary>
29 /// RuntimeFramework represents a particular version
30 /// of a common language runtime implementation.
31 /// </summary>
32 public sealed class RuntimeFramework
34 private RuntimeType runtime;
35 private Version version;
37 /// <summary>
38 /// Constructor
39 /// </summary>
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;
48 /// <summary>
49 /// Static method to return a RuntimeFramework object
50 /// for the frameowrk that is currently in use.
51 /// </summary>
52 public static RuntimeFramework CurrentFramework
54 get
56 RuntimeType runtime = Type.GetType( "Mono.Runtime", false ) != null
57 ? RuntimeType.Mono : RuntimeType.Net;
59 return new RuntimeFramework( runtime, Environment.Version );
63 /// <summary>
64 /// The type of this runtime framework
65 /// </summary>
66 public RuntimeType Runtime
68 get { return runtime; }
71 /// <summary>
72 /// The version of this runtime framework
73 /// </summary>
74 public Version Version
76 get { return version; }
79 /// <summary>
80 /// Gets a display string for the particular framework version
81 /// </summary>
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();