public XamlILNodeEmitResult Emit(IXamlAstNode node, XamlEmitContext <IXamlILEmitter, XamlILNodeEmitResult> context, IXamlILEmitter codeGen)
            {
                if (!(node is HandleRootObjectScopeNode))
                {
                    return(null);
                }
                var types = context.GetAvaloniaTypes();

                var next       = codeGen.DefineLabel();
                var scopeField = context.RuntimeContext.ContextType.Fields.First(f =>
                                                                                 f.Name == AvaloniaXamlIlLanguage.ContextNameScopeFieldName);

                using (var local = codeGen.LocalsPool.GetLocal(types.StyledElement))
                {
                    codeGen
                    .Isinst(types.StyledElement)
                    .Dup()
                    .Stloc(local.Local)
                    .Brfalse(next)
                    .Ldloc(local.Local)
                    .Ldloc(context.ContextLocal)
                    .Ldfld(scopeField)
                    .EmitCall(types.NameScopeSetNameScope, true)
                    .MarkLabel(next)
                    .Ldloc(context.ContextLocal)
                    .Ldfld(scopeField)
                    .EmitCall(types.INameScopeComplete, true);
                }

                return(XamlILNodeEmitResult.Void(1));
            }
                public XamlILNodeEmitResult Emit(IXamlAstNode node, XamlEmitContext <IXamlILEmitter, XamlILNodeEmitResult> context, IXamlILEmitter codeGen)
                {
                    if (!(node is HandleRootObjectScopeNode))
                    {
                        return(null);
                    }

                    var controlType = context.Configuration.TypeSystem.FindType("Robust.Client.UserInterface.Control");

                    var next              = codeGen.DefineLabel();
                    var dontAbsorb        = codeGen.DefineLabel();
                    var end               = codeGen.DefineLabel();
                    var contextScopeField = context.RuntimeContext.ContextType.Fields.First(f =>
                                                                                            f.Name == XamlCompiler.ContextNameScopeFieldName);
                    var controlNameScopeField = controlType.Fields.First(f => f.Name == "NameScope");
                    var nameScopeType         = context.Configuration.TypeSystem
                                                .FindType("Robust.Client.UserInterface.XAML.NameScope");
                    var nameScopeCompleteMethod = nameScopeType.Methods.First(m => m.Name == "Complete");
                    var nameScopeAbsorbMethod   = nameScopeType.Methods.First(m => m.Name == "Absorb");

                    using (var local = codeGen.LocalsPool.GetLocal(controlType))
                    {
                        codeGen
                        .Isinst(controlType)
                        .Dup()
                        .Stloc(local.Local) //store control in local field
                        .Brfalse(next)      //if control is null, move to next (this should never happen but whatev, avalonia does it)
                        .Ldloc(context.ContextLocal)
                        .Ldfld(contextScopeField)
                        .Ldloc(local.Local)           //load control from local field
                        .Ldfld(controlNameScopeField) //load namescope field from control
                        .EmitCall(nameScopeAbsorbMethod, true)
                        .Ldloc(local.Local)           //load control
                        .Ldloc(context.ContextLocal)  //load contextObject
                        .Ldfld(contextScopeField)     //load namescope field from context obj
                        .Stfld(controlNameScopeField) //store namescope field in control
                        .MarkLabel(next)
                        .Ldloc(context.ContextLocal)
                        .Ldfld(contextScopeField)
                        .EmitCall(nameScopeCompleteMethod, true);     //set the namescope as complete
                    }

                    return(XamlILNodeEmitResult.Void(1));
                }