From c87faff8a1c06464e2184be5193201b9d143b307 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Tue, 6 Dec 2022 09:49:09 -0800 Subject: [PATCH 1/2] Update TextAlignmentExtensionsGenerator --- .../TextAlignmentExtensionsGenerator.cs | 8 ++-- .../TextAlignmentExtensionsTests.cs | 41 ++++++++++++++++++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/CommunityToolkit.Maui.Markup.SourceGenerators/SourceGenerators/TextAlignmentExtensionsGenerator.cs b/src/CommunityToolkit.Maui.Markup.SourceGenerators/SourceGenerators/TextAlignmentExtensionsGenerator.cs index c78dfd6f..f3d07ba2 100644 --- a/src/CommunityToolkit.Maui.Markup.SourceGenerators/SourceGenerators/TextAlignmentExtensionsGenerator.cs +++ b/src/CommunityToolkit.Maui.Markup.SourceGenerators/SourceGenerators/TextAlignmentExtensionsGenerator.cs @@ -54,7 +54,7 @@ static void Execute(SourceProductionContext context, Compilation compilation, Im foreach (var namedTypeSymbol in mauiTextAlignmentImplementors) { - textAlignmentClassList.Add((namedTypeSymbol.Name, "public", namedTypeSymbol.ContainingNamespace.ToDisplayString(), namedTypeSymbol.TypeArguments.GetGenericTypeArgumentsString(), namedTypeSymbol.GetGenericTypeConstraintsAsString())); + textAlignmentClassList.Add((namedTypeSymbol.Name, "internal", namedTypeSymbol.ContainingNamespace.ToDisplayString(), namedTypeSymbol.TypeArguments.GetGenericTypeArgumentsString(), namedTypeSymbol.GetGenericTypeConstraintsAsString())); } // Collect All Classes in User Library that Implement ITextAlignment @@ -114,7 +114,7 @@ namespace CommunityToolkit.Maui.Markup /// /// Extension Methods for /// - static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @" + " + textAlignmentClass.ClassAcessModifier + @" static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @" { /// /// = @@ -242,7 +242,7 @@ namespace LeftToRight /// /// Extension Methods for /// - " + textAlignmentClass.ClassAcessModifier + " static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @" + " + textAlignmentClass.ClassAcessModifier + @" static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @" { /// /// = @@ -289,7 +289,7 @@ namespace RightToLeft /// /// Extension methods for /// - " + textAlignmentClass.ClassAcessModifier + " static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @" + " + textAlignmentClass.ClassAcessModifier + @" static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @" { /// /// = diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/TextAlignmentExtensionsTests.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/TextAlignmentExtensionsTests.cs index 9de538c2..b39a7afd 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/TextAlignmentExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/TextAlignmentExtensionsTests.cs @@ -1,4 +1,8 @@ -using CommunityToolkit.Maui.Markup.UnitTests.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using CommunityToolkit.Maui.Markup.UnitTests.Base; using CommunityToolkit.Maui.UnitTests.Extensions.TextAlignmentExtensions; using Microsoft.Maui; using Microsoft.Maui.Controls; @@ -212,6 +216,41 @@ public void SupportCustomTextAlignment() .TextCenter()); } + [Test] + public void AccessModifierForMauiControlsShouldNotBePublic() + { + foreach (var (generatedType, control) in GetGeneratedTextAlignmentExtensionTypes()) + { + if (control.Assembly == typeof(Button).Assembly) + { + Assert.False(generatedType.IsPublic); + } + } + } + + [Test] + public void AccessModifierForCustomControlsShouldMatchTheControl() + { + var executingAssembly = Assembly.GetExecutingAssembly(); + + foreach (var (generatedType, control) in GetGeneratedTextAlignmentExtensionTypes()) + { + if (control.Assembly == executingAssembly) + { + Assert.AreEqual(control.IsPublic, generatedType.IsPublic); + } + } + } + + static IEnumerable<(Type generatedType, Type control)> GetGeneratedTextAlignmentExtensionTypes() + { + return from type in Assembly.GetExecutingAssembly().GetTypes() + where type.Name.StartsWith("TextAlignmentExtensions_") + let method = type.GetMethods().Single(m => m.Name.StartsWith("TextLeft") || m.Name.StartsWith("TextStart")) + let control = method.GetParameters()[0].ParameterType.BaseType + select (type, control); + } + class DerivedFromSearchBar : SearchBar { } } From ccd88562e6d6a624e48fbdad950a6678bfc8c144 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Sat, 3 Dec 2022 11:50:54 -0800 Subject: [PATCH 2/2] `dotnet format` --- .../TextAlignmentExtensionsTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/TextAlignmentExtensionsTests.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/TextAlignmentExtensionsTests.cs index b39a7afd..b28be8bc 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/TextAlignmentExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/TextAlignmentExtensionsTests.cs @@ -413,9 +413,9 @@ class InternalTextAlignmentView : View, ICustomTextAlignment public TextAlignment HorizontalTextAlignment { get; set; } public TextAlignment VerticalTextAlignment { get; set; } - } - - // Ensures custom ITextAlignment interfaces are supported + } + + // Ensures custom ITextAlignment interfaces are supported interface ICustomTextAlignment : ITextAlignment { @@ -461,8 +461,8 @@ public class GenericPicker : where TA : notnull, ISomeInterface where TB : class where TC : struct - where TD : class, ISomeInterface, new() - //TE has no constraints + where TD : class, ISomeInterface, new() + //TE has no constraints where TF : notnull where TG : unmanaged where TH : ISomeInterface?