From a13576b25edda7d9fe6b04290810d35430c1eb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20G=C3=B6n=C3=BClta=C5=9F?= Date: Mon, 25 Nov 2024 00:45:03 +0300 Subject: [PATCH] An error was fixed in the codes generated for ReadOnly lists. #155 --- .../Extensions/ExtensionGenerator.cs | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/FmgLib.MauiMarkup.Generator/Extensions/ExtensionGenerator.cs b/src/FmgLib.MauiMarkup.Generator/Extensions/ExtensionGenerator.cs index f4cffb8..3e56b6f 100644 --- a/src/FmgLib.MauiMarkup.Generator/Extensions/ExtensionGenerator.cs +++ b/src/FmgLib.MauiMarkup.Generator/Extensions/ExtensionGenerator.cs @@ -1,4 +1,5 @@ using Microsoft.CodeAnalysis; + using System; using System.Collections; using System.Collections.Generic; @@ -109,23 +110,23 @@ void GenerateClassExtensionBody() (_.Type.Name.Contains(nameof(IList)) || _.Type.AllInterfaces.Any(e => e.Name.Contains(nameof(IList))) || _.Type.Name.Contains(nameof(ICollection)) || _.Type.AllInterfaces.Any(e => e.Name.Contains(nameof(ICollection)))) && _.Type.AllInterfaces.Any(e => e.Name.Contains(nameof(IEnumerable))) && !_.Type.Name.Equals(nameof(String), StringComparison.InvariantCultureIgnoreCase)) + .Where(_ => !(_.Type.Name.Contains("IReadOnlyList") || _.Type.AllInterfaces.Any(e => e.Name.Contains("IReadOnlyList")))) .ToList(); - - var events = mainSymbol - .GetMembers() - .Where(_ => _.Kind == SymbolKind.Event) - .Where(_ => _.DeclaredAccessibility == Accessibility.Public) - .Cast() - .Where(_ => !_.Name.Contains('.')) - .Where(_ => (_.ContainingType is INamedTypeSymbol namedTypeSymbol) && namedTypeSymbol.GetFullyQualifiedName() == mainSymbol.GetFullyQualifiedName()) - .Where(_ => !_.GetAttributes().Any(_ => _.AttributeClass.EnsureNotNull().Equals(editorBrowsableAttribute, SymbolEqualityComparer.Default))) - .Where(_ => !_.GetAttributes().Any(_ => _.AttributeClass.EnsureNotNull().Name == "ObsoleteAttribute" || _.AttributeClass.EnsureNotNull().Name == "Obsolete")) - .GroupBy(_ => _.Name, StringComparer.OrdinalIgnoreCase) - .Select(_ => _.First()) - .OrderBy(_ => _.Name) - .ToArray(); + var events = mainSymbol + .GetMembers() + .Where(_ => _.Kind == SymbolKind.Event) + .Where(_ => _.DeclaredAccessibility == Accessibility.Public) + .Cast() + .Where(_ => !_.Name.Contains('.')) + .Where(_ => (_.ContainingType is INamedTypeSymbol namedTypeSymbol) && namedTypeSymbol.GetFullyQualifiedName() == mainSymbol.GetFullyQualifiedName()) + .Where(_ => !_.GetAttributes().Any(_ => _.AttributeClass.EnsureNotNull().Equals(editorBrowsableAttribute, SymbolEqualityComparer.Default))) + .Where(_ => !_.GetAttributes().Any(_ => _.AttributeClass.EnsureNotNull().Name == "ObsoleteAttribute" || _.AttributeClass.EnsureNotNull().Name == "Obsolete")) + .GroupBy(_ => _.Name, StringComparer.OrdinalIgnoreCase) + .Select(_ => _.First()) + .OrderBy(_ => _.Name) + .ToArray(); if (attachedModel == null) { @@ -217,7 +218,8 @@ void GenerateExtensionMethod(IPropertySymbol propertySymbol, bool isOnlyList = f namedListType.BaseType.TypeArguments.Length == 1) typeName = namedListType.BaseType.TypeArguments[0].ToDisplayString(); - GenerateExtensionMethod_ContentProp_List(info, typeName); + if (!string.IsNullOrEmpty(typeName)) + GenerateExtensionMethod_ContentProp_List(info, typeName); } else { @@ -242,7 +244,7 @@ void GenerateExtensionMethod(IPropertySymbol propertySymbol, bool isOnlyList = f GenerateExtensionMethod_AnimateTo(info, "ColorTransform"); } } - + isGeneratedExtension = true; } }