From 6fd810f0dcf9252524f4a3459f798a8f1e5a363c Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 19 Apr 2019 13:22:56 +0300 Subject: [PATCH] Disable Cecil backend in runtime compiler based on a property --- .../Avalonia.Markup.Xaml.csproj | 8 +++-- .../XamlIl/AvaloniaXamlIlRuntimeCompiler.cs | 33 ++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj index d4d3b1814e..fe1c20eec9 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj +++ b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj @@ -1,7 +1,9 @@  netstandard2.0 - PCL;NETSTANDARD;NETSTANDARD2_0;HAS_TYPE_CONVERTER;HAS_CUSTOM_ATTRIBUTE_PROVIDER + PCL;NETSTANDARD;NETSTANDARD2_0;HAS_TYPE_CONVERTER;HAS_CUSTOM_ATTRIBUTE_PROVIDER; + false + $(DefineConstants);RUNTIME_XAML_CECIL False false CS1591 @@ -70,7 +72,7 @@ - + @@ -85,7 +87,7 @@ - + diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/AvaloniaXamlIlRuntimeCompiler.cs b/src/Markup/Avalonia.Markup.Xaml/XamlIl/AvaloniaXamlIlRuntimeCompiler.cs index 3eb493ab58..62d87ac285 100644 --- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/AvaloniaXamlIlRuntimeCompiler.cs +++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/AvaloniaXamlIlRuntimeCompiler.cs @@ -9,16 +9,18 @@ using System.Reflection.Emit; using System.Runtime.InteropServices; using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions; using Avalonia.Platform; -using Mono.Cecil; -using XamlIl.Ast; using XamlIl.Transform; using XamlIl.TypeSystem; +#if RUNTIME_XAML_CECIL using TypeAttributes = Mono.Cecil.TypeAttributes; - +using Mono.Cecil; +using XamlIl.Ast; +#endif namespace Avalonia.Markup.Xaml.XamlIl { public static class AvaloniaXamlIlRuntimeCompiler { +#if !RUNTIME_XAML_CECIL private static SreTypeSystem _sreTypeSystem; private static ModuleBuilder _sreBuilder; private static XamlIlLanguageTypeMappings _sreMappings; @@ -84,13 +86,6 @@ namespace Avalonia.Markup.Xaml.XamlIl _sreXmlns = XamlIlXmlnsMappings.Resolve(_sreTypeSystem, _sreMappings); } - public static object Load(Stream stream, Assembly localAssembly, object rootInstance, Uri uri) - { - string xaml; - using (var sr = new StreamReader(stream)) - xaml = sr.ReadToEnd(); - return LoadCecil(xaml, localAssembly, rootInstance, uri); - } static object LoadSre(string xaml, Assembly localAssembly, object rootInstance, Uri uri) { @@ -107,6 +102,7 @@ namespace Avalonia.Markup.Xaml.XamlIl DumpRuntimeCompilationResults(); } } + static object LoadSreCore(string xaml, Assembly localAssembly, object rootInstance, Uri uri) { @@ -130,7 +126,8 @@ namespace Avalonia.Markup.Xaml.XamlIl return LoadOrPopulate(created, rootInstance); } - +#endif + static object LoadOrPopulate(Type created, object rootInstance) { var isp = Expression.Parameter(typeof(IServiceProvider)); @@ -153,7 +150,20 @@ namespace Avalonia.Markup.Xaml.XamlIl return rootInstance; } } + + public static object Load(Stream stream, Assembly localAssembly, object rootInstance, Uri uri) + { + string xaml; + using (var sr = new StreamReader(stream)) + xaml = sr.ReadToEnd(); +#if RUNTIME_XAML_CECIL + return LoadCecil(xaml, localAssembly, rootInstance, uri); +#else + return LoadSre(xaml, localAssembly, rootInstance, uri); +#endif + } +#if RUNTIME_XAML_CECIL private static Dictionary populate, Func build)> s_CecilCache = @@ -232,5 +242,6 @@ namespace Avalonia.Markup.Xaml.XamlIl _cecilGeneratedCache[safeUri] = loaded; return LoadOrPopulate(loaded, rootInstance); } +#endif } }