From d04a4a3cf23c51d8401364d13b9201bf27873618 Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Mon, 25 Jul 2016 21:40:34 +0200 Subject: [XamlC] fix a bug in the debugging code introduced last week (#267) --- Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs | 4 ++-- Xamarin.Forms.Build.Tasks/XamlCTask.cs | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'Xamarin.Forms.Build.Tasks') diff --git a/Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs b/Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs index e0f81972..c4744cc2 100644 --- a/Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs +++ b/Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs @@ -69,8 +69,8 @@ namespace Xamarin.Forms.Build.Tasks } var initCompRuntime = typeDef.Methods.FirstOrDefault(md => md.Name == "__InitComponentRuntime"); if (initCompRuntime == null) { - LogLine(2, "no __InitComponentRuntime found... skipped."); - continue; + LogLine(2, "no __InitComponentRuntime found... duplicating."); + initCompRuntime = DuplicateMethodDef(typeDef, initComp, "__InitComponentRuntime"); } // IL_0000: ldarg.0 diff --git a/Xamarin.Forms.Build.Tasks/XamlCTask.cs b/Xamarin.Forms.Build.Tasks/XamlCTask.cs index b6387c0f..ae2a66d0 100644 --- a/Xamarin.Forms.Build.Tasks/XamlCTask.cs +++ b/Xamarin.Forms.Build.Tasks/XamlCTask.cs @@ -232,13 +232,12 @@ namespace Xamarin.Forms.Build.Tasks } LogLine(2, ""); - if (typeDef.Methods.FirstOrDefault(md => md.Name == "__InitComponentRuntime") != null) { + var initCompRuntime = typeDef.Methods.FirstOrDefault(md => md.Name == "__InitComponentRuntime"); + if (initCompRuntime != null) LogLine(2, " __InitComponentRuntime already exists... not duplicating"); - } else { + else { LogString(2, " Duplicating {0}.InitializeComponent () into {0}.__InitComponentRuntime ... ", typeDef.Name); - var initCompRuntime = new MethodDefinition("__InitComponentRuntime", initComp.Attributes, initComp.ReturnType); - initCompRuntime.Body = initComp.Body; - typeDef.Methods.Add(initCompRuntime); + initCompRuntime = DuplicateMethodDef(typeDef, initComp, "__InitComponentRuntime"); LogLine(2, "done."); } @@ -293,7 +292,6 @@ namespace Xamarin.Forms.Build.Tasks il.Emit(OpCodes.Callvirt, func); il.Emit(OpCodes.Brfalse, nop); il.Emit(OpCodes.Ldarg_0); - var initCompRuntime = typeDef.Methods.FirstOrDefault(md => md.Name == "__InitComponentRuntime"); il.Emit(OpCodes.Call, initCompRuntime); il.Emit(OpCodes.Ret); il.Append(nop); @@ -404,6 +402,14 @@ namespace Xamarin.Forms.Build.Tasks return success; } + protected static MethodDefinition DuplicateMethodDef(TypeDefinition typeDef, MethodDefinition methodDef, string newName) + { + var dup = new MethodDefinition(newName, methodDef.Attributes, methodDef.ReturnType); + dup.Body = methodDef.Body; + typeDef.Methods.Add(dup); + return dup; + } + static ILRootNode ParseXaml(Stream stream, TypeReference typeReference) { ILRootNode rootnode = null; -- cgit v1.2.3