Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Generated Classes for TextAlignmentExtensions for .NET MAUI Controls internal #161

Merged
merged 2 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,7 +114,7 @@ namespace CommunityToolkit.Maui.Markup
/// <summary>
/// Extension Methods for <see cref=""ITextAlignment""/>
/// </summary>
static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @"
" + textAlignmentClass.ClassAcessModifier + @" static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @"
{
/// <summary>
/// <see cref=""ITextAlignment.HorizontalTextAlignment""/> = <see cref=""TextAlignment.Start""/>
Expand Down Expand Up @@ -242,7 +242,7 @@ namespace LeftToRight
/// <summary>
/// Extension Methods for <see cref=""ITextAlignment""/>
/// </summary>
" + textAlignmentClass.ClassAcessModifier + " static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @"
" + textAlignmentClass.ClassAcessModifier + @" static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @"
{
/// <summary>
/// <see cref=""ITextAlignment.HorizontalTextAlignment""/> = <see cref=""TextAlignment.Start""/>
Expand Down Expand Up @@ -289,7 +289,7 @@ namespace RightToLeft
/// <summary>
/// Extension methods for <see cref=""ITextAlignment""/>
/// </summary>
" + textAlignmentClass.ClassAcessModifier + " static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @"
" + textAlignmentClass.ClassAcessModifier + @" static partial class TextAlignmentExtensions_" + textAlignmentClass.ClassName + @"
{
/// <summary>
/// <see cref=""ITextAlignment.HorizontalTextAlignment""/> = <see cref=""TextAlignment.End""/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 { }
}

Expand Down Expand Up @@ -374,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
{

Expand Down Expand Up @@ -422,8 +461,8 @@ public class GenericPicker<TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ, TK, TL, TM> :
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?
Expand Down