From d355007c57a71184e56f2d92d49cf83c05401413 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 17 Jul 2020 16:33:31 +0300 Subject: [PATCH] Extracted runtime XAML loader to a separate package --- .gitmodules | 2 +- Avalonia.sln | 27 ++++++ Directory.Build.props | 1 + .../Avalonia.Build.Tasks.csproj | 10 +-- .../DesignWindowLoader.cs | 7 +- .../Remote/FileWatcherTransport.cs | 10 ++- .../HtmlTransport/webapp/package-lock.json | 28 +++++-- .../Remote/RemoteDesignerEntryPoint.cs | 8 +- .../Avalonia.Markup.Xaml.Loader.csproj | 14 ++++ .../AvaloniaRuntimeXamlLoader.cs | 42 ++++++++++ .../AvaloniaXamlIlRuntimeCompiler.cs | 0 .../AvaloniaXamlIlCompiler.cs | 0 .../AvaloniaXamlIlCompilerConfiguration.cs | 0 .../AvaloniaXamlIlLanguage.cs | 0 .../Transformers/AddNameScopeRegistration.cs | 0 .../AvaloniaBindingExtensionTransformer.cs | 0 .../AvaloniaXamlIlAvaloniaPropertyResolver.cs | 0 .../AvaloniaXamlIlBindingPathParser.cs | 0 .../AvaloniaXamlIlBindingPathTransformer.cs | 0 ...iaXamlIlCompiledBindingsMetadataRemover.cs | 0 ...IlConstructorServiceProviderTransformer.cs | 0 ...olTemplateTargetTypeMetadataTransformer.cs | 0 ...valoniaXamlIlDataContextTypeTransformer.cs | 0 ...aloniaXamlIlDesignPropertiesTransformer.cs | 0 .../AvaloniaXamlIlMetadataRemover.cs | 0 .../AvaloniaXamlIlPropertyPathTransformer.cs | 0 ...lIlResolveByNameMarkupExtensionReplacer.cs | 0 ...valoniaXamlIlRootObjectScopeTransformer.cs | 0 .../AvaloniaXamlIlSelectorTransformer.cs | 0 .../AvaloniaXamlIlSetterTransformer.cs | 0 ...mlIlTransformInstanceAttachedProperties.cs | 0 ...ransformSyntheticCompiledBindingMembers.cs | 0 ...amlIlTransitionsTypeMetadataTransformer.cs | 0 .../AvaloniaXamlIlWellKnownTypes.cs | 0 .../IgnoredDirectivesTransformer.cs | 0 .../Transformers/XNameTransformer.cs | 0 .../XamlIlAvaloniaPropertyHelper.cs | 0 .../XamlIlBindingPathHelper.cs | 0 .../XamlIlClrPropertyInfoHelper.cs | 0 ...amlIlPropertyInfoAccessorFactoryEmitter.cs | 0 .../IncludeXamlIlSre.props | 12 +++ .../xamlil.github | 0 .../Avalonia.Markup.Xaml.csproj | 36 -------- .../AvaloniaXamlLoader.cs | 52 +----------- .../MarkupExtensions/ResourceInclude.cs | 3 +- .../Styling/StyleInclude.cs | 3 +- .../Avalonia.Designer.HostApp.csproj | 6 +- .../DesignXamlLoader.cs | 16 ++++ .../Avalonia.Designer.HostApp/Program.cs | 4 +- .../Avalonia.Controls.UnitTests.csproj | 1 + .../ContextMenuTests.cs | 6 +- .../TabControlTests.cs | 4 +- .../Avalonia.Markup.Xaml.UnitTests.csproj | 1 + .../Converters/ConverterTests.cs | 2 +- .../Converters/MultiValueConverterTests.cs | 3 +- .../Converters/NullableConverterTests.cs | 3 +- .../PointsListTypeConverterTests.cs | 3 +- .../Converters/ValueConverterTests.cs | 3 +- .../Data/BindingTests.cs | 9 +- .../Data/BindingTests_Method.cs | 9 +- .../Data/BindingTests_TemplatedParent.cs | 3 +- .../MarkupExtensions/BindingExtensionTests.cs | 9 +- .../CompiledBindingExtensionTests.cs | 69 +++++---------- .../DynamicResourceExtensionTests.cs | 78 ++++++----------- .../MarkupExtensions/ResourceIncludeTests.cs | 6 +- .../StaticResourceExtensionTests.cs | 57 +++++-------- .../StyleIncludeTests.cs | 3 +- .../StyleTests.cs | 3 +- .../Xaml/BasicTests.cs | 83 +++++++++---------- .../Xaml/BindingTests.cs | 47 ++++------- .../Xaml/BindingTests_RelativeSource.cs | 42 ++++------ .../Xaml/ControlBindingTests.cs | 9 +- .../Xaml/DataTemplateTests.cs | 9 +- .../Xaml/EventTests.cs | 9 +- .../Xaml/ResourceDictionaryTests.cs | 6 +- .../Xaml/StyleTests.cs | 44 ++++------ .../Xaml/TreeDataTemplateTests.cs | 3 +- .../Xaml/XamlIlTests.cs | 32 +++---- .../Avalonia.ReactiveUI.UnitTests.csproj | 3 +- .../AvaloniaActivationForViewFetcherTest.cs | 6 +- .../Avalonia.Skia.UnitTests.csproj | 1 + tests/Avalonia.UnitTests/TestServices.cs | 3 +- 82 files changed, 386 insertions(+), 464 deletions(-) create mode 100644 src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj create mode 100644 src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaRuntimeXamlLoader.cs rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/AvaloniaXamlIlRuntimeCompiler.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/AvaloniaXamlIlCompiler.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/AvaloniaXamlIlLanguage.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AddNameScopeRegistration.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaBindingExtensionTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlAvaloniaPropertyResolver.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlCompiledBindingsMetadataRemover.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlConstructorServiceProviderTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlControlTemplateTargetTypeMetadataTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlDataContextTypeTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlDesignPropertiesTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlMetadataRemover.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlPropertyPathTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlResolveByNameMarkupExtensionReplacer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlRootObjectScopeTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlSelectorTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlSetterTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlTransitionsTypeMetadataTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/IgnoredDirectivesTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/Transformers/XNameTransformer.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/XamlIlBindingPathHelper.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/XamlIlClrPropertyInfoHelper.cs (100%) rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/CompilerExtensions/XamlIlPropertyInfoAccessorFactoryEmitter.cs (100%) create mode 100644 src/Markup/Avalonia.Markup.Xaml.Loader/IncludeXamlIlSre.props rename src/Markup/{Avalonia.Markup.Xaml/XamlIl => Avalonia.Markup.Xaml.Loader}/xamlil.github (100%) create mode 100644 src/tools/Avalonia.Designer.HostApp/DesignXamlLoader.cs diff --git a/.gitmodules b/.gitmodules index 9dbc50ef612..2d11fdfa9e1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,5 +2,5 @@ path = nukebuild/Numerge url = https://github.com/kekekeks/Numerge.git [submodule "src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github"] - path = src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github + path = src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github url = https://github.com/kekekeks/XamlX.git diff --git a/Avalonia.sln b/Avalonia.sln index 4ab647a25e3..4954260e12d 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -211,6 +211,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Headless", "src\Av EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Headless.Vnc", "src\Avalonia.Headless.Vnc\Avalonia.Headless.Vnc.csproj", "{B859AE7C-F34F-4A9E-88AE-E0E7229FDE1E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Markup.Xaml.Loader", "src\Markup\Avalonia.Markup.Xaml.Loader\Avalonia.Markup.Xaml.Loader.csproj", "{909A8CBD-7D0E-42FD-B841-022AD8925820}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution src\Shared\RenderHelpers\RenderHelpers.projitems*{3c4c0cb4-0c0f-4450-a37b-148c84ff905f}*SharedItemsImports = 13 @@ -1998,6 +2000,30 @@ Global {C42D2FC1-A531-4ED4-84B9-89AEC7C962FC}.Release|iPhone.Build.0 = Release|Any CPU {C42D2FC1-A531-4ED4-84B9-89AEC7C962FC}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {C42D2FC1-A531-4ED4-84B9-89AEC7C962FC}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.AppStore|iPhone.Build.0 = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Debug|Any CPU.Build.0 = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Debug|iPhone.Build.0 = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Release|Any CPU.ActiveCfg = Release|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Release|Any CPU.Build.0 = Release|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Release|iPhone.ActiveCfg = Release|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Release|iPhone.Build.0 = Release|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {909A8CBD-7D0E-42FD-B841-022AD8925820}.Release|iPhoneSimulator.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2056,6 +2082,7 @@ Global {AF915D5C-AB00-4EA0-B5E6-001F4AE84E68} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} {351337F5-D66F-461B-A957-4EF60BDB4BA6} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} {3C84E04B-36CF-4D0D-B965-C26DD649D1F3} = {A0CC0258-D18C-4AB3-854F-7101680FC3F9} + {909A8CBD-7D0E-42FD-B841-022AD8925820} = {8B6A8209-894F-4BA1-B880-965FD453982C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {87366D66-1391-4D90-8999-95A620AD786A} diff --git a/Directory.Build.props b/Directory.Build.props index 1f26df9bbc1..b41f8c488e3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,6 @@ $(MSBuildThisFileDirectory)build-intermediate/nuget + $(MSBuildThisFileDirectory)\src\tools\Avalonia.Designer.HostApp\bin\$(Configuration)\netcoreapp2.0\Avalonia.Designer.HostApp.dll diff --git a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj index 7117fd51a25..490364c0d87 100644 --- a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj +++ b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj @@ -17,14 +17,14 @@ Shared/AvaloniaResourceXamlInfo.cs - + XamlIlExtensions/%(RecursiveDir)%(FileName)%(Extension) - + XamlIl/%(RecursiveDir)%(FileName)%(Extension) - + XamlIl.Cecil/%(RecursiveDir)%(FileName)%(Extension) @@ -57,8 +57,8 @@ Markup/%(RecursiveDir)%(FileName)%(Extension) - - + + diff --git a/src/Avalonia.DesignerSupport/DesignWindowLoader.cs b/src/Avalonia.DesignerSupport/DesignWindowLoader.cs index f3bb0edce50..d7c6cc3693e 100644 --- a/src/Avalonia.DesignerSupport/DesignWindowLoader.cs +++ b/src/Avalonia.DesignerSupport/DesignWindowLoader.cs @@ -12,13 +12,18 @@ namespace Avalonia.DesignerSupport { public class DesignWindowLoader { + public interface IDesignXamlLoader + { + object Load(MemoryStream stream, Assembly localAsm, object o, Uri baseUri); + } + public static Window LoadDesignerWindow(string xaml, string assemblyPath, string xamlFileProjectPath) { Window window; Control control; using (PlatformManager.DesignerMode()) { - var loader = new AvaloniaXamlLoader() {IsDesignMode = true}; + var loader = AvaloniaLocator.Current.GetService(); var stream = new MemoryStream(Encoding.UTF8.GetBytes(xaml)); diff --git a/src/Avalonia.DesignerSupport/Remote/FileWatcherTransport.cs b/src/Avalonia.DesignerSupport/Remote/FileWatcherTransport.cs index 0cb71dd2177..0448a5c05d7 100644 --- a/src/Avalonia.DesignerSupport/Remote/FileWatcherTransport.cs +++ b/src/Avalonia.DesignerSupport/Remote/FileWatcherTransport.cs @@ -9,12 +9,14 @@ namespace Avalonia.DesignerSupport.Remote { class FileWatcherTransport : IAvaloniaRemoteTransportConnection, ITransportWithEnforcedMethod { + private readonly string _appPath; private string _path; private string _lastContents; private bool _disposed; - public FileWatcherTransport(Uri file) + public FileWatcherTransport(Uri file, string appPath) { + _appPath = appPath; _path = file.LocalPath; } @@ -73,7 +75,11 @@ async void UpdaterThread() { Console.WriteLine("Triggering XAML update"); _lastContents = data; - _onMessage?.Invoke(this, new UpdateXamlMessage { Xaml = data }); + _onMessage?.Invoke(this, new UpdateXamlMessage + { + Xaml = data, + AssemblyPath = _appPath + }); } await Task.Delay(100); diff --git a/src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/package-lock.json b/src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/package-lock.json index 87536c670f5..028027a9744 100644 --- a/src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/package-lock.json +++ b/src/Avalonia.DesignerSupport/Remote/HtmlTransport/webapp/package-lock.json @@ -3564,12 +3564,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3584,17 +3586,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -3711,7 +3716,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3723,6 +3729,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3737,6 +3744,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3744,12 +3752,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3768,6 +3778,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3848,7 +3859,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3860,6 +3872,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3981,6 +3994,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs index e61fe82c413..3e26ded22db 100644 --- a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs +++ b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs @@ -112,8 +112,9 @@ static CommandLineArgs ParseCommandLineArgs(string[] args) return rv; } - static IAvaloniaRemoteTransportConnection CreateTransport(Uri transport) + static IAvaloniaRemoteTransportConnection CreateTransport(CommandLineArgs args) { + var transport = args.Transport; if (transport.Scheme == "tcp-bson") { return new BsonTcpTransport().Connect(IPAddress.Parse(transport.Host), transport.Port).Result; @@ -121,7 +122,7 @@ static IAvaloniaRemoteTransportConnection CreateTransport(Uri transport) if (transport.Scheme == "file") { - return new FileWatcherTransport(transport); + return new FileWatcherTransport(transport, args.AppPath); } PrintUsage(); return null; @@ -160,7 +161,7 @@ public IAvaloniaRemoteTransportConnection ConfigureApp(IAvaloniaRemoteTransportC public static void Main(string[] cmdline) { var args = ParseCommandLineArgs(cmdline); - var transport = CreateTransport(args.Transport); + var transport = CreateTransport(args); if (transport is ITransportWithEnforcedMethod enforcedMethod) args.Method = enforcedMethod.PreviewerMethod; var asm = Assembly.LoadFile(System.IO.Path.GetFullPath(args.AppPath)); @@ -234,6 +235,7 @@ private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transp } catch (Exception e) { + Console.Error.WriteLine(e.ToString()); s_transport.Send(new UpdateXamlResultMessage { Error = e.ToString(), diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj b/src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj new file mode 100644 index 00000000000..768545eb7e7 --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj @@ -0,0 +1,14 @@ + + + + netstandard2.0 + true + + + + + + + + + diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaRuntimeXamlLoader.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaRuntimeXamlLoader.cs new file mode 100644 index 00000000000..4569970d010 --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaRuntimeXamlLoader.cs @@ -0,0 +1,42 @@ +using System; +using System.IO; +using System.Reflection; +using System.Text; +using Avalonia.Markup.Xaml.XamlIl; +// ReSharper disable CheckNamespace + +namespace Avalonia.Markup.Xaml +{ + public static class AvaloniaRuntimeXamlLoader + { + /// + /// Loads XAML from a string. + /// + /// The string containing the XAML. + /// Default assembly for clr-namespace: + /// + /// The optional instance into which the XAML should be loaded. + /// + /// The loaded object. + public static object Load(string xaml, Assembly localAssembly = null, object rootInstance = null, Uri uri = null, bool designMode = false) + { + Contract.Requires(xaml != null); + + using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xaml))) + { + return Load(stream, localAssembly, rootInstance, uri, designMode); + } + } + + public static object Load(Stream stream, Assembly localAssembly, object rootInstance = null, Uri uri = null, + bool designMode = false) + => AvaloniaXamlIlRuntimeCompiler.Load(stream, localAssembly, rootInstance, uri, designMode); + + public static object Parse(string xaml, Assembly localAssembly = null) + => Load(xaml, localAssembly); + + public static T Parse(string xaml, Assembly localAssembly = null) + => (T)Parse(xaml, localAssembly); + + } +} diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/AvaloniaXamlIlRuntimeCompiler.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/AvaloniaXamlIlRuntimeCompiler.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlCompiler.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompiler.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlCompiler.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompiler.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlLanguage.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguage.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlLanguage.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguage.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AddNameScopeRegistration.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AddNameScopeRegistration.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AddNameScopeRegistration.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AddNameScopeRegistration.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaBindingExtensionTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaBindingExtensionTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaBindingExtensionTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaBindingExtensionTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlAvaloniaPropertyResolver.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlAvaloniaPropertyResolver.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlAvaloniaPropertyResolver.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlAvaloniaPropertyResolver.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlCompiledBindingsMetadataRemover.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlCompiledBindingsMetadataRemover.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlCompiledBindingsMetadataRemover.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlCompiledBindingsMetadataRemover.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlConstructorServiceProviderTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlConstructorServiceProviderTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlConstructorServiceProviderTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlConstructorServiceProviderTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlControlTemplateTargetTypeMetadataTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlControlTemplateTargetTypeMetadataTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlControlTemplateTargetTypeMetadataTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlControlTemplateTargetTypeMetadataTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlDataContextTypeTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlDataContextTypeTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlDataContextTypeTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlDataContextTypeTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlDesignPropertiesTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlDesignPropertiesTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlDesignPropertiesTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlDesignPropertiesTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlMetadataRemover.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlMetadataRemover.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlMetadataRemover.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlMetadataRemover.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlPropertyPathTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlPropertyPathTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlPropertyPathTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlPropertyPathTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlResolveByNameMarkupExtensionReplacer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlResolveByNameMarkupExtensionReplacer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlResolveByNameMarkupExtensionReplacer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlResolveByNameMarkupExtensionReplacer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlRootObjectScopeTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlRootObjectScopeTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlRootObjectScopeTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlRootObjectScopeTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlSelectorTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlSelectorTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlSelectorTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlSelectorTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlSetterTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlSetterTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlSetterTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlSetterTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlTransitionsTypeMetadataTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransitionsTypeMetadataTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlTransitionsTypeMetadataTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransitionsTypeMetadataTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/IgnoredDirectivesTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/IgnoredDirectivesTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/IgnoredDirectivesTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/IgnoredDirectivesTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/XNameTransformer.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/XNameTransformer.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/Transformers/XNameTransformer.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/XNameTransformer.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlBindingPathHelper.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlBindingPathHelper.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlClrPropertyInfoHelper.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlClrPropertyInfoHelper.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlClrPropertyInfoHelper.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlClrPropertyInfoHelper.cs diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlPropertyInfoAccessorFactoryEmitter.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlPropertyInfoAccessorFactoryEmitter.cs similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlPropertyInfoAccessorFactoryEmitter.cs rename to src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlPropertyInfoAccessorFactoryEmitter.cs diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/IncludeXamlIlSre.props b/src/Markup/Avalonia.Markup.Xaml.Loader/IncludeXamlIlSre.props new file mode 100644 index 00000000000..c902fa956a7 --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/IncludeXamlIlSre.props @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github b/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github similarity index 100% rename from src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github rename to src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github diff --git a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj index 3979312ce09..24428253aa0 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj +++ b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj @@ -45,44 +45,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -96,8 +62,6 @@ - - diff --git a/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs b/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs index 5c21037924c..0e81ca2be8a 100644 --- a/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs +++ b/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs @@ -10,10 +10,8 @@ namespace Avalonia.Markup.Xaml /// /// Loads XAML for a avalonia application. /// - public class AvaloniaXamlLoader + public static class AvaloniaXamlLoader { - public bool IsDesignMode { get; set; } - /// /// Loads the XAML into a Avalonia component. /// @@ -32,7 +30,7 @@ public static void Load(object obj) /// A base URI to use if is relative. /// /// The loaded object. - public object Load(Uri uri, Uri baseUri = null) + public static object Load(Uri uri, Uri baseUri = null) { Contract.Requires(uri != null); @@ -56,51 +54,9 @@ public object Load(Uri uri, Uri baseUri = null) return compiledResult; } - - var asset = assetLocator.OpenAndGetAssembly(uri, baseUri); - using (var stream = asset.stream) - { - var absoluteUri = uri.IsAbsoluteUri ? uri : new Uri(baseUri, uri); - return Load(stream, asset.assembly, null, absoluteUri); - } + throw new XamlLoadException( + $"No precompiled XAML found for {uri} (baseUri: {baseUri}), make sure to specify x:Class and include your XAML file as AvaloniaResource"); } - /// - /// Loads XAML from a string. - /// - /// The string containing the XAML. - /// Default assembly for clr-namespace: - /// - /// The optional instance into which the XAML should be loaded. - /// - /// The loaded object. - public object Load(string xaml, Assembly localAssembly = null, object rootInstance = null) - { - Contract.Requires(xaml != null); - - using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xaml))) - { - return Load(stream, localAssembly, rootInstance); - } - } - - /// - /// Loads XAML from a stream. - /// - /// The stream containing the XAML. - /// Default assembly for clr-namespace - /// - /// The optional instance into which the XAML should be loaded. - /// - /// The URI of the XAML - /// The loaded object. - public object Load(Stream stream, Assembly localAssembly, object rootInstance = null, Uri uri = null) - => AvaloniaXamlIlRuntimeCompiler.Load(stream, localAssembly, rootInstance, uri, IsDesignMode); - - public static object Parse(string xaml, Assembly localAssembly = null) - => new AvaloniaXamlLoader().Load(xaml, localAssembly); - - public static T Parse(string xaml, Assembly localAssembly = null) - => (T)Parse(xaml, localAssembly); } } diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs index 0cedf4f3645..b6137aa89f7 100644 --- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs +++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs @@ -25,8 +25,7 @@ public IResourceDictionary Loaded if (_loaded == null) { _isLoading = true; - var loader = new AvaloniaXamlLoader(); - _loaded = (IResourceDictionary)loader.Load(Source, _baseUri); + _loaded = (IResourceDictionary)AvaloniaXamlLoader.Load(Source, _baseUri); _isLoading = false; } diff --git a/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs b/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs index ea9042f7790..607b552c281 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs @@ -51,8 +51,7 @@ public IStyle Loaded if (_loaded == null) { _isLoading = true; - var loader = new AvaloniaXamlLoader(); - var loaded = (IStyle)loader.Load(Source, _baseUri); + var loaded = (IStyle)AvaloniaXamlLoader.Load(Source, _baseUri); _loaded = new[] { loaded }; _isLoading = false; } diff --git a/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj b/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj index 1c7077870a8..aa40f1d75a6 100644 --- a/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj +++ b/src/tools/Avalonia.Designer.HostApp/Avalonia.Designer.HostApp.csproj @@ -18,6 +18,10 @@ - + + + + + diff --git a/src/tools/Avalonia.Designer.HostApp/DesignXamlLoader.cs b/src/tools/Avalonia.Designer.HostApp/DesignXamlLoader.cs new file mode 100644 index 00000000000..b873027765b --- /dev/null +++ b/src/tools/Avalonia.Designer.HostApp/DesignXamlLoader.cs @@ -0,0 +1,16 @@ +using System; +using System.IO; +using System.Reflection; +using Avalonia.DesignerSupport; +using Avalonia.Markup.Xaml.XamlIl; + +namespace Avalonia.Designer.HostApp +{ + class DesignXamlLoader : DesignWindowLoader.IDesignXamlLoader + { + public object Load(MemoryStream stream, Assembly localAsm, object o, Uri baseUri) + { + return AvaloniaXamlIlRuntimeCompiler.Load(stream, localAsm, o, baseUri, true); + } + } +} diff --git a/src/tools/Avalonia.Designer.HostApp/Program.cs b/src/tools/Avalonia.Designer.HostApp/Program.cs index 3163e1fbc38..7469f946a48 100644 --- a/src/tools/Avalonia.Designer.HostApp/Program.cs +++ b/src/tools/Avalonia.Designer.HostApp/Program.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Reflection; +using Avalonia.DesignerSupport; namespace Avalonia.Designer.HostApp { @@ -40,8 +41,9 @@ static void Exec(string[] args) public static void Main(string[] args) #endif { + AvaloniaLocator.CurrentMutable.Bind() + .ToConstant(new DesignXamlLoader()); Avalonia.DesignerSupport.Remote.RemoteDesignerEntryPoint.Main(args); } - } } diff --git a/tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj b/tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj index 2ca93dcf56b..19c4454d3d1 100644 --- a/tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj +++ b/tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj @@ -13,6 +13,7 @@ + diff --git a/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs b/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs index 9a81d19bb93..cf8f7c266ab 100644 --- a/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs @@ -191,8 +191,7 @@ public void Context_Menu_In_Resources_Can_Be_Shared() "; - var loader = new AvaloniaXamlLoader(); - var window = (Window)loader.Load(xaml); + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var target1 = window.Find("target1"); var target2 = window.Find("target2"); var mouse = new MouseTestHelper(); @@ -235,8 +234,7 @@ public void Context_Menu_Can_Be_Set_In_Style() "; - var loader = new AvaloniaXamlLoader(); - var window = (Window)loader.Load(xaml); + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var target1 = window.Find("target1"); var target2 = window.Find("target2"); var mouse = new MouseTestHelper(); diff --git a/tests/Avalonia.Controls.UnitTests/TabControlTests.cs b/tests/Avalonia.Controls.UnitTests/TabControlTests.cs index db9211ac3c0..fd52aeb9af2 100644 --- a/tests/Avalonia.Controls.UnitTests/TabControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/TabControlTests.cs @@ -8,6 +8,7 @@ using Avalonia.Controls.Templates; using Avalonia.Controls.Utils; using Avalonia.LogicalTree; +using Avalonia.Markup.Xaml; using Avalonia.Styling; using Avalonia.UnitTests; using Xunit; @@ -338,8 +339,7 @@ public void Can_Have_Empty_Tab_Control() xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> "; - var loader = new Markup.Xaml.AvaloniaXamlLoader(); - var window = (Window)loader.Load(xaml); + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var tabControl = window.FindControl("tabs"); tabControl.DataContext = new { Tabs = new List() }; diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj b/tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj index e8c4daa7bc0..ad3592294dd 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj @@ -11,6 +11,7 @@ + diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/ConverterTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/ConverterTests.cs index b424003ed60..c9420f1696d 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/ConverterTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/ConverterTests.cs @@ -9,7 +9,7 @@ public class ConverterTests : XamlTestBase public void Bug_2228_Relative_Uris_Should_Be_Correctly_Parsed() { var testClass = typeof(TestClassWithUri); - var parsed = AvaloniaXamlLoader.Parse( + var parsed = AvaloniaRuntimeXamlLoader.Parse( $"<{testClass.Name} xmlns='clr-namespace:{testClass.Namespace}' Uri='/test'/>", testClass.Assembly); Assert.False(parsed.Uri.IsAbsoluteUri); diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/MultiValueConverterTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/MultiValueConverterTests.cs index a77723afe1b..466ae1bf7cd 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/MultiValueConverterTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/MultiValueConverterTests.cs @@ -29,8 +29,7 @@ public void MultiValueConverter_Special_Values_Work() "; - var loader = new AvaloniaXamlLoader(); - var window = (Window)loader.Load(xaml); + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var textBlock = window.FindControl("textBlock"); window.ApplyTemplate(); diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/NullableConverterTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/NullableConverterTests.cs index cdd40ed80f2..eb8851c80b7 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/NullableConverterTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/NullableConverterTests.cs @@ -22,8 +22,7 @@ public void Nullable_Types_Should_Still_Be_Converted_Properly() xmlns='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Converters' Thickness = '5' Orientation='Vertical' >"; - var loader = new AvaloniaXamlLoader(); - var data = (ClassWithNullableProperties)loader.Load(xaml, typeof(ClassWithNullableProperties).Assembly); + var data = (ClassWithNullableProperties)AvaloniaRuntimeXamlLoader.Load(xaml, typeof(ClassWithNullableProperties).Assembly); Assert.Equal(new Thickness(5), data.Thickness); Assert.Equal(Orientation.Vertical, data.Orientation); } diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/PointsListTypeConverterTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/PointsListTypeConverterTests.cs index b060905f38d..3b729e9cd80 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/PointsListTypeConverterTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/PointsListTypeConverterTests.cs @@ -31,8 +31,7 @@ public void TypeConverter_Should_Parse(string input) public void Should_Parse_Points_in_Xaml(string input) { var xaml = $""; - var loader = new AvaloniaXamlLoader(); - var polygon = (Polygon)loader.Load(xaml); + var polygon = (Polygon)AvaloniaRuntimeXamlLoader.Load(xaml); var points = polygon.Points; diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/ValueConverterTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/ValueConverterTests.cs index 5e698117c36..4d5983e2763 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/ValueConverterTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/ValueConverterTests.cs @@ -21,8 +21,7 @@ public void ValueConverter_Special_Values_Work() xmlns:c='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Converters;assembly=Avalonia.Markup.Xaml.UnitTests'> "; - var loader = new AvaloniaXamlLoader(); - var window = (Window)loader.Load(xaml); + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var textBlock = window.FindControl("textBlock"); window.ApplyTemplate(); diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests.cs index 6730e3134d5..afc4a36feae 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests.cs @@ -24,8 +24,7 @@ public void Binding_With_Null_Path_Works() xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> "; - var loader = new AvaloniaXamlLoader(); - var window = (Window)loader.Load(xaml); + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var textBlock = window.FindControl("textBlock"); window.DataContext = "foo"; @@ -45,8 +44,7 @@ public void Binding_To_DoNothing_Works() xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> "; - var loader = new AvaloniaXamlLoader(); - var window = (Window)loader.Load(xaml); + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var textBlock = window.FindControl("textBlock"); window.ApplyTemplate(); @@ -86,8 +84,7 @@ public void MultiBinding_TemplatedParent_Works() "; - var loader = new AvaloniaXamlLoader(); - var window = (Window)loader.Load(xaml); + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var textBox = window.FindControl("textBox"); window.ApplyTemplate(); diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Method.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Method.cs index b2b4c4da1ab..a7a004bd49b 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Method.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Method.cs @@ -20,8 +20,7 @@ public void Binding_Method_To_Command_Works() xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> "; - var loader = new AvaloniaXamlLoader(); - var window = (Window)loader.Load(xaml); + var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var button = window.FindControl "; - var control = AvaloniaXamlLoader.Parse(xaml); + var control = AvaloniaRuntimeXamlLoader.Parse(xaml); var button = control.FindControl "; - var control = AvaloniaXamlLoader.Parse(xaml); + var control = AvaloniaRuntimeXamlLoader.Parse(xaml); var button = control.FindControl