static SharedRuntimeState() { if (Runtime.AssemblyContext.IsMono) { CurrentRuntime = EDotNetRuntime.Mono; } else if (Runtime.AssemblyContext.IsCoreCLR) { CurrentRuntime = EDotNetRuntime.CoreCLR; } else { CurrentRuntime = EDotNetRuntime.CLR; } }
public static bool IsRuntimeLoaded(EDotNetRuntime runtime) { return((Instance->LoadedRuntimes & runtime) == runtime); }
public static bool IsRuntimeInitialized(EDotNetRuntime runtime) { return((Instance->InitializedRuntimes & runtime) == runtime); }
private static bool HasMoreThanOneFlag(EDotNetRuntime flags) { return((flags & (flags - 1)) != 0);// has more than 1 flag }
private static unsafe void SetDotNetRuntime(string[] args) { // It's probably possible to dynamically load runtimes by adding a function to SharedRuntimeState (and slightly modifying // the current load checks inside of CSharpLoader::Load) const string enableMoreRuntimesStr = "Only one runtime has been loaded. Modify /USharp/Binaries/Managed/Runtimes/DotNetRuntime.txt to add more runtimes and then reopen the editor."; if (args != null && args.Length > 0) { bool handled = true; switch (args[0].ToLower()) { case "diag": { // Diagnostics... FMessage.Log("============================================================================================"); FMessage.Log("Loaded modules in " + SharedRuntimeState.CurrentRuntime + ":"); foreach (System.Reflection.Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { FMessage.Log(assembly.FullName); } // Also print out the loaded AppDomain instances when under the .NET Framework (CLR) if (AssemblyContext.IsCLR) { FMessage.Log("================ Domains:"); string[] appDomains = AppDomainDiagnostic.GetNames(); if (appDomains != null) { foreach (string appDomain in appDomains) { FMessage.Log(appDomain); } } } } break; case "reload": { SharedRuntimeState.Instance->Reload = true; } break; default: handled = false; break; } if (handled) { return; } if (SharedRuntimeState.HaveMultipleRuntimesLoaded()) { EDotNetRuntime runtime = EDotNetRuntime.None; switch (args[0].ToLower()) { case "mono": runtime = EDotNetRuntime.Mono; break; case "clr": runtime = EDotNetRuntime.CLR; break; case "coreclr": runtime = EDotNetRuntime.CoreCLR; break; } if (runtime == EDotNetRuntime.None) { FMessage.Log("Unknown runtime '" + args[0] + "'. Current runtime: " + SharedRuntimeState.GetRuntimeInfo(true)); } else if (!SharedRuntimeState.IsRuntimeLoaded(runtime)) { FMessage.Log(runtime + " isn't loaded. Current runtime: " + SharedRuntimeState.GetRuntimeInfo(true)); } else if (SharedRuntimeState.Instance->NextRuntime != EDotNetRuntime.None) { FMessage.Log("Runtime change already queued (" + SharedRuntimeState.Instance->NextRuntime.ToString() + ")"); } else if (SharedRuntimeState.Instance->Reload) { FMessage.Log("The active runtime is currently reloading (" + SharedRuntimeState.Instance->ActiveRuntime + ")"); } else if (SharedRuntimeState.Instance->ActiveRuntime == runtime) { FMessage.Log(runtime.ToString() + " is already the active runtime"); } else { SharedRuntimeState.Instance->RuntimeCounter++; SharedRuntimeState.Instance->NextRuntime = runtime; FMessage.Log("Changing runtime to " + runtime.ToString() + "..."); } } else { FMessage.Log(ELogVerbosity.Error, enableMoreRuntimesStr); FMessage.Log("Runtime: " + SharedRuntimeState.GetRuntimeInfo(true)); } } else { if (!SharedRuntimeState.HaveMultipleRuntimesLoaded()) { FMessage.Log(enableMoreRuntimesStr); } FMessage.Log("Runtime: " + SharedRuntimeState.GetRuntimeInfo(true)); } }