Last active
March 18, 2017 09:04
-
-
Save kostrse/fbcc56f79883e4f1a9eb87a75c3fffd6 to your computer and use it in GitHub Desktop.
Determine .NET runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.Reflection | |
let getMethod (bindingFlags: BindingFlags) (methodName: string) (t: Type): MethodInfo option = | |
if t <> null then | |
Some (t.GetMethod(methodName, bindingFlags)) | |
else | |
None | |
let privateMethod (methodName: string) (t: Type) = | |
t |> getMethod (BindingFlags.NonPublic) methodName | |
let privateStaticMethod (methodName: string) (t: Type) = | |
t |> getMethod (BindingFlags.NonPublic ||| BindingFlags.Static) methodName | |
let clrVersion (): string = Environment.Version.ToString() | |
let monoVersion (runtime: Type): string = | |
let methodGetDisplayName = runtime |> privateStaticMethod "GetDisplayName" | |
match methodGetDisplayName with | |
| Some (m) -> string (m.Invoke(null, null)) | |
| None -> "Unknown version" | |
let whatPlatform () = | |
match Type.GetType("Mono.Runtime") with | |
| null -> sprintf "CLR %s" (clrVersion ()) | |
| monoRuntime -> sprintf "Mono %s" (monoVersion monoRuntime) | |
whatPlatform() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment