public static Window instance {
get {
GCHandle gcHandle = (GCHandle) Window_instance();
IntPtr ptr = Window_instance();
if (ptr == IntPtr.Zero) {
D.assert(false, () => "AssertionError: Window.instance is null. Please enclose your code with window scope (detailed examples can be found in the README file)");
return null;
}
GCHandle gcHandle = (GCHandle) ptr;
return (Window) gcHandle.Target;
return static_cast<UIMonoState*>(MonoState::Current());
bool UIMonoState::EnsureCurrentIsolate() {
return MonoState::EnsureCurrentIsolate();
void UIMonoState::SetWindow(std::unique_ptr<Window> window) {
window_ = std::move(window);
public:
static UIMonoState* Current();
static bool EnsureCurrentIsolate();
Window* window() const { return window_.get(); }
const TaskRunners& GetTaskRunners() const;
UIWIDGETS_API(Mono_Handle) Window_instance() {
if (!UIMonoState::EnsureCurrentIsolate()) {
return nullptr;
return UIMonoState::Current()->window()->mono_window();
return isolate_data->get();
bool MonoState::EnsureCurrentIsolate() {
return Mono_CurrentIsolate() != nullptr;
MonoState* MonoState::Current() {
auto isolate_data =
static_cast<std::shared_ptr<MonoState>*>(Mono_CurrentIsolateData());
static MonoState* From(Mono_Isolate isolate);
static MonoState* Current();
std::weak_ptr<MonoState> GetWeakPtr();