Skip to content

Instantly share code, notes, and snippets.

@kostrse
Last active March 18, 2017 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostrse/fbcc56f79883e4f1a9eb87a75c3fffd6 to your computer and use it in GitHub Desktop.
Save kostrse/fbcc56f79883e4f1a9eb87a75c3fffd6 to your computer and use it in GitHub Desktop.
Determine .NET runtime
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