Skip to content

Commit

Permalink
Generator: don't map Element properties as Lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamescaper committed Jan 4, 2025
1 parent f8d7a94 commit 4bc6695
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<MC.Layout, IView>(builder, sequence++, ChildContent, x => x.Children);
var itemTypeName = GetTypeNameAndAddNamespace(itemType);
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions src/BlazorBindings.Maui/Properties/AttributeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)])]
Expand Down

0 comments on commit 4bc6695

Please sign in to comment.