bool TryCoreCompile(MethodDefinition initComp, MethodDefinition initCompRuntime, ILRootNode rootnode, string xamlFilePath, out Exception exception) { try { var body = new MethodBody(initComp); var module = body.Method.Module; body.InitLocals = true; var il = body.GetILProcessor(); var resourcePath = GetPathForType(module, initComp.DeclaringType); il.Emit(Nop); var visitorContext = new ILContext(il, body, module) { DefineDebug = DebugSymbols || (!string.IsNullOrEmpty(DebugType) && DebugType.ToLowerInvariant() != "none"), XamlFilePath = xamlFilePath }; rootnode.Accept(new XamlNodeVisitor((node, parent) => node.Parent = parent), null); rootnode.Accept(new ExpandMarkupsVisitor(visitorContext), null); rootnode.Accept(new PruneIgnoredNodesVisitor(), null); rootnode.Accept(new CreateObjectVisitor(visitorContext), null); rootnode.Accept(new SetNamescopesAndRegisterNamesVisitor(visitorContext), null); rootnode.Accept(new SetFieldVisitor(visitorContext), null); rootnode.Accept(new SetResourcesVisitor(visitorContext), null); rootnode.Accept(new SetPropertiesVisitor(visitorContext, true), null); il.Emit(Ret); initComp.Body = body; exception = null; return(true); } catch (Exception e) { exception = e; return(false); } }
bool TryCoreCompile(MethodDefinition initComp, MethodDefinition initCompRuntime, ILRootNode rootnode, string xamlFilePath, out Exception exception) { try { var body = new MethodBody(initComp); var module = body.Method.Module; body.InitLocals = true; var il = body.GetILProcessor(); var resourcePath = GetPathForType(module, initComp.DeclaringType); il.Emit(Nop); if (initCompRuntime != null) { // Generating branching code for the Previewer //First using the ResourceLoader var nop = Instruction.Create(Nop); // if (ResourceLoader.IsEnabled && ... il.Emit(Call, module.ImportPropertyGetterReference(("Microsoft.Maui.Controls", "Microsoft.Maui.Controls.Internals", "ResourceLoader"), "IsEnabled", isStatic: true)); il.Emit(Brfalse, nop); il.Emit(Newobj, module.ImportCtorReference(("Microsoft.Maui.Controls", "Microsoft.Maui.Controls.Internals", "ResourceLoader/ResourceLoadingQuery"), 0)); //AssemblyName il.Emit(Dup); //dup the RLQ il.Emit(Ldtoken, module.ImportReference(initComp.DeclaringType)); il.Emit(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));