From 1c1c15abcd1f2e782725ff76f3c366098fbbe006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Rag=C3=A1ny-N=C3=A9meth?= Date: Wed, 31 Aug 2022 16:03:12 +0200 Subject: [PATCH] Add DynamicallyAccessedMembers attributes to extension methods (#23) --- .gitignore | 5 +++- .../MauiAppBuilderExtensions.cs | 23 +++++++++++++++---- .../Playground.Maui/Playground.Maui.csproj | 11 +-------- global.json | 7 ++++++ 4 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 global.json diff --git a/.gitignore b/.gitignore index 90dbc02..f272d5e 100644 --- a/.gitignore +++ b/.gitignore @@ -363,4 +363,7 @@ MigrationBackup/ FodyWeavers.xsd # MacOS folder info -.DS_Store \ No newline at end of file +.DS_Store + +# Rider +.idea \ No newline at end of file diff --git a/MaterialColorUtilities.Maui/MauiAppBuilderExtensions.cs b/MaterialColorUtilities.Maui/MauiAppBuilderExtensions.cs index 8189d62..e2ef837 100644 --- a/MaterialColorUtilities.Maui/MauiAppBuilderExtensions.cs +++ b/MaterialColorUtilities.Maui/MauiAppBuilderExtensions.cs @@ -1,4 +1,6 @@ -namespace MaterialColorUtilities.Maui; +using System.Diagnostics.CodeAnalysis; + +namespace MaterialColorUtilities.Maui; public static class MauiAppBuilderExtensions { @@ -13,15 +15,26 @@ public static MauiAppBuilder UseMaterialDynamicColors( Action configureOptions) => builder.UseMaterialDynamicColors(configureOptions); - public static MauiAppBuilder UseMaterialDynamicColors(this MauiAppBuilder builder) + public static MauiAppBuilder UseMaterialDynamicColors< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] + TDynamicColorService> + (this MauiAppBuilder builder) where TDynamicColorService : class, IDynamicColorService => builder.UseMaterialDynamicColors(_ => { }); - public static MauiAppBuilder UseMaterialDynamicColors(this MauiAppBuilder builder, uint fallbackSeed) + public static MauiAppBuilder UseMaterialDynamicColors< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] + TDynamicColorService> + ( + this MauiAppBuilder builder, uint fallbackSeed + ) where TDynamicColorService : class, IDynamicColorService => builder.UseMaterialDynamicColors(opt => opt.FallbackSeed = (int)fallbackSeed); - public static MauiAppBuilder UseMaterialDynamicColors( + public static MauiAppBuilder UseMaterialDynamicColors< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] + TDynamicColorService> + ( this MauiAppBuilder builder, Action configureOptions ) @@ -32,4 +45,4 @@ Action configureOptions builder.Services.AddSingleton>(); return builder; } -} +} \ No newline at end of file diff --git a/Playground/Playground.Maui/Playground.Maui.csproj b/Playground/Playground.Maui/Playground.Maui.csproj index 920f772..babfd25 100644 --- a/Playground/Playground.Maui/Playground.Maui.csproj +++ b/Playground/Playground.Maui/Playground.Maui.csproj @@ -59,16 +59,7 @@ - - - - MSBuild:Compile - - - MSBuild:Compile - - - + diff --git a/global.json b/global.json new file mode 100644 index 0000000..e42a955 --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "6.0.400", + "rollForward": "latestMinor", + "allowPrerelease": true + } +} \ No newline at end of file