Browse Source
Merge pull request #9637 from AvaloniaUI/public-ctors
Do not require matching ctor, if top level element
pull/9464/head
Nikita Tsukanov
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
25 additions and
2 deletions
-
src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs
-
src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github
-
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
|
|
|
@ -234,7 +234,7 @@ namespace Avalonia.Markup.Xaml.XamlIl |
|
|
|
parsedDocuments.Add(new XamlDocumentResource(parsed, document.BaseUri?.ToString(), null, null, |
|
|
|
builder, |
|
|
|
compiler.DefinePopulateMethod(builder, parsed, AvaloniaXamlIlCompiler.PopulateName, true), |
|
|
|
compiler.DefineBuildMethod(builder, parsed, AvaloniaXamlIlCompiler.BuildName, true))); |
|
|
|
document.RootInstance is null ? compiler.DefineBuildMethod(builder, parsed, AvaloniaXamlIlCompiler.BuildName, true) : null)); |
|
|
|
originalDocuments.Add(document); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1 +1 @@ |
|
|
|
Subproject commit 491de981dd4433ee58bc9540e2cd4a5d168f8168 |
|
|
|
Subproject commit 5e498f8bcca403a34aff5efc825cbb4e12b7fa8e |
|
|
|
@ -899,6 +899,17 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|
|
|
Assert.Equal("Foo", target.Text); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Parse_And_Populate_Type_Without_Public_Ctor() |
|
|
|
{ |
|
|
|
var xaml = @"<ObjectWithoutPublicCtor xmlns='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml' Test2='World' />"; |
|
|
|
var target = (ObjectWithoutPublicCtor)AvaloniaRuntimeXamlLoader.Load(xaml, rootInstance: new ObjectWithoutPublicCtor("Hello")); |
|
|
|
|
|
|
|
Assert.NotNull(target); |
|
|
|
Assert.Equal("World", target.Test2); |
|
|
|
Assert.Equal("Hello", target.Test1); |
|
|
|
} |
|
|
|
|
|
|
|
private class SelectedItemsViewModel : INotifyPropertyChanged |
|
|
|
{ |
|
|
|
public string[] Items { get; set; } |
|
|
|
@ -928,6 +939,18 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|
|
|
Child = child; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class ObjectWithoutPublicCtor |
|
|
|
{ |
|
|
|
public ObjectWithoutPublicCtor(string param) |
|
|
|
{ |
|
|
|
Test1 = param; |
|
|
|
} |
|
|
|
|
|
|
|
public string Test1 { get; set; } |
|
|
|
|
|
|
|
public string Test2 { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
public class ObjectWithAddChildOfT : IAddChild, IAddChild<string> |
|
|
|
{ |
|
|
|
|