From 4bc6695925e458707c933d17dc03b1a1919db63f Mon Sep 17 00:00:00 2001 From: Oleksandr Liakhevych Date: Sat, 4 Jan 2025 16:00:33 +0200 Subject: [PATCH] Generator: don't map Element properties as Lists --- .../GeneratedPropertyInfo.RenderFragment.cs | 8 +++++++- src/BlazorBindings.Maui/Properties/AttributeInfo.cs | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/BlazorBindings.Maui.ComponentGenerator/GeneratedPropertyInfo.RenderFragment.cs b/src/BlazorBindings.Maui.ComponentGenerator/GeneratedPropertyInfo.RenderFragment.cs index 0a226aa3..676bb434 100644 --- a/src/BlazorBindings.Maui.ComponentGenerator/GeneratedPropertyInfo.RenderFragment.cs +++ b/src/BlazorBindings.Maui.ComponentGenerator/GeneratedPropertyInfo.RenderFragment.cs @@ -63,7 +63,7 @@ public string RenderContentProperty() var itemTypeName = GenericTypeArgument is null ? "T" : GetTypeNameAndAddNamespace(GenericTypeArgument); return $"\r\n RenderTreeBuilderHelper.AddDataTemplateProperty<{MauiContainingTypeName}, {itemTypeName}>(builder, sequence++, {ComponentPropertyName}, (x, template) => x.{_propertyInfo.Name} = template);"; } - else if (!ForceContent && IsIList(_propertyType, out itemType)) + else if (!ForceContent && IsIList(_propertyType, out itemType) && !IsElement(Compilation, _propertyType)) { // RenderTreeBuilderHelper.AddListContentProperty(builder, sequence++, ChildContent, x => x.Children); var itemTypeName = GetTypeNameAndAddNamespace(itemType); @@ -157,6 +157,12 @@ private static bool IsContent(Compilation compilation, ITypeSymbol type) }); } + private static bool IsElement(Compilation compilation, ITypeSymbol type) + { + var elementSymbol = compilation.GetTypeByMetadataName("Microsoft.Maui.Controls.Element"); + return compilation.ClassifyConversion(type, elementSymbol) is { IsIdentity: true } or { IsReference: true, IsImplicit: true }; + } + private static bool IsIList(ITypeSymbol type, out ITypeSymbol itemType) { var isList = TypeEqualsIList(type, out var outItemType) || type.AllInterfaces.Any(i => IsIList(i, out outItemType)); diff --git a/src/BlazorBindings.Maui/Properties/AttributeInfo.cs b/src/BlazorBindings.Maui/Properties/AttributeInfo.cs index a4f71788..3782793a 100644 --- a/src/BlazorBindings.Maui/Properties/AttributeInfo.cs +++ b/src/BlazorBindings.Maui/Properties/AttributeInfo.cs @@ -94,8 +94,7 @@ [assembly: GenerateComponent(typeof(StructuredItemsView), ContentProperties = [nameof(StructuredItemsView.Header), nameof(StructuredItemsView.Footer)], Exclude = [nameof(StructuredItemsView.HeaderTemplate), nameof(StructuredItemsView.FooterTemplate)])] -[assembly: GenerateComponent(typeof(SwipeView), - ContentProperties = [nameof(SwipeView.LeftItems), nameof(SwipeView.RightItems), nameof(SwipeView.TopItems), nameof(SwipeView.BottomItems)])] +[assembly: GenerateComponent(typeof(SwipeView))] [assembly: GenerateComponent(typeof(SwipeItems), Exclude = [nameof(SwipeItems.CollectionChanged)])] [assembly: GenerateComponent(typeof(TabbedPage), Exclude = [nameof(TabbedPage.ItemsSource), nameof(TabbedPage.ItemTemplate)])] [assembly: GenerateComponent(typeof(TableView), Exclude = [nameof(TableView.Root)])]