Browse Source

Disable Cecil backend in runtime compiler based on a property

xamlil-debug-info
Nikita Tsukanov 7 years ago
parent
commit
6fd810f0dc
  1. 8
      src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj
  2. 33
      src/Markup/Avalonia.Markup.Xaml/XamlIl/AvaloniaXamlIlRuntimeCompiler.cs

8
src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj

@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DefineConstants>PCL;NETSTANDARD;NETSTANDARD2_0;HAS_TYPE_CONVERTER;HAS_CUSTOM_ATTRIBUTE_PROVIDER</DefineConstants>
<DefineConstants>PCL;NETSTANDARD;NETSTANDARD2_0;HAS_TYPE_CONVERTER;HAS_CUSTOM_ATTRIBUTE_PROVIDER;</DefineConstants>
<UseCecil>false</UseCecil>
<DefineConstants Condition="$(UseCecil) == true">$(DefineConstants);RUNTIME_XAML_CECIL</DefineConstants>
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
<EnableDefaultItems>false</EnableDefaultItems>
<NoWarn>CS1591</NoWarn>
@ -70,7 +72,7 @@
<Compile Include="XamlLoadException.cs" />
<Compile Include="PortableXaml\portable.xaml.github\src\Portable.Xaml\**\*.cs" Exclude="PortableXaml\portable.xaml.github\src\Portable.Xaml\Assembly\**\*.cs" />
<Compile Include="XamlIl\xamlil.github\src\XamlIl\**\*.cs" />
<Compile Include="XamlIl\xamlil.github\src\XamlIl.Cecil\**\*.cs" />
<Compile Condition="$(UseCecil) == true" Include="XamlIl\xamlil.github\src\XamlIl.Cecil\**\*.cs" />
<Compile Remove="XamlIl\xamlil.github\**\obj\**\*.cs" />
<Compile Include="..\Avalonia.Markup\Markup\Parsers\SelectorGrammar.cs" />
</ItemGroup>
@ -85,7 +87,7 @@
<ProjectReference Include="..\..\Avalonia.Styling\Avalonia.Styling.csproj" />
<ProjectReference Include="..\Avalonia.Markup\Avalonia.Markup.csproj" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="Mono.Cecil" Version="0.10.3" />
<PackageReference Condition="$(UseCecil) == true" Include="Mono.Cecil" Version="0.10.3" />
</ItemGroup>
<ItemGroup>
<Content Include="XamlIl\CompilerExtensions\README.md" />

33
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<string, (Action<IServiceProvider, object> populate, Func<IServiceProvider, object>
build)>
s_CecilCache =
@ -232,5 +242,6 @@ namespace Avalonia.Markup.Xaml.XamlIl
_cecilGeneratedCache[safeUri] = loaded;
return LoadOrPopulate(loaded, rootInstance);
}
#endif
}
}

Loading…
Cancel
Save