copied mono-api-diff.cs from mono-2-2 branch so new patch can be applied and history...
[mono.git] / mcs / nunit24 / NUnitCore / interfaces / RuntimeFramework.cs
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
6 \r
7 using System;\r
8 using System.Reflection;\r
9 \r
10 namespace NUnit.Core\r
11 {\r
12         /// <summary>\r
13         /// Enumeration identifying a common language \r
14         /// runtime implementation.\r
15         /// </summary>\r
16         public enum RuntimeType\r
17         {\r
18                 /// <summary>Microsoft .NET Framework</summary>\r
19                 Net,\r
20                 /// <summary>Microsoft .NET Compact Framework</summary>\r
21                 NetCF,\r
22                 /// <summary>Microsoft Shared Source CLI</summary>\r
23                 SSCLI,\r
24                 /// <summary>Mono</summary>\r
25                 Mono\r
26         }\r
27 \r
28         /// <summary>\r
29         /// RuntimeFramework represents a particular version\r
30         /// of a common language runtime implementation.\r
31         /// </summary>\r
32         public sealed class RuntimeFramework\r
33         {\r
34                 private RuntimeType runtime;\r
35                 private Version version;\r
36 \r
37                 /// <summary>\r
38                 /// Constructor\r
39                 /// </summary>\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
43                 {\r
44                         this.runtime = runtime;\r
45                         this.version = version;\r
46                 }\r
47 \r
48                 /// <summary>\r
49                 /// Static method to return a RuntimeFramework object\r
50                 /// for the frameowrk that is currently in use.\r
51                 /// </summary>\r
52                 public static RuntimeFramework CurrentFramework\r
53                 {\r
54                         get \r
55                         { \r
56                                 RuntimeType runtime = Type.GetType( "Mono.Runtime", false ) != null\r
57                                         ? RuntimeType.Mono : RuntimeType.Net;\r
58 \r
59                                 return new RuntimeFramework( runtime, Environment.Version );\r
60                         }\r
61                 }\r
62 \r
63                 /// <summary>\r
64                 /// The type of this runtime framework\r
65                 /// </summary>\r
66                 public RuntimeType Runtime\r
67                 {\r
68                         get { return runtime; }\r
69                 }\r
70 \r
71                 /// <summary>\r
72                 /// The version of this runtime framework\r
73                 /// </summary>\r
74                 public Version Version\r
75                 {\r
76                         get { return version; }\r
77                 }\r
78 \r
79                 /// <summary>\r
80                 /// Gets a display string for the particular framework version\r
81                 /// </summary>\r
82                 /// <returns>A string used to display the framework in use</returns>\r
83                 public string GetDisplayName()\r
84                 {\r
85                         if ( runtime == RuntimeType.Mono )\r
86                         {\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
92                         }\r
93 \r
94                         return runtime.ToString() + " " + Version.ToString();\r
95                 }\r
96         }\r
97 }\r