Skip to content

Commit

Permalink
Add DynamicallyAccessedMembers attributes to extension methods (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
albi005 authored Aug 31, 2022
1 parent b1dd609 commit 1c1c15a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,7 @@ MigrationBackup/
FodyWeavers.xsd

# MacOS folder info
.DS_Store
.DS_Store

# Rider
.idea
23 changes: 18 additions & 5 deletions MaterialColorUtilities.Maui/MauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MaterialColorUtilities.Maui;
using System.Diagnostics.CodeAnalysis;

namespace MaterialColorUtilities.Maui;

public static class MauiAppBuilderExtensions
{
Expand All @@ -13,15 +15,26 @@ public static MauiAppBuilder UseMaterialDynamicColors(
Action<DynamicColorOptions> configureOptions)
=> builder.UseMaterialDynamicColors<DynamicColorService>(configureOptions);

public static MauiAppBuilder UseMaterialDynamicColors<TDynamicColorService>(this MauiAppBuilder builder)
public static MauiAppBuilder UseMaterialDynamicColors<
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
TDynamicColorService>
(this MauiAppBuilder builder)
where TDynamicColorService : class, IDynamicColorService
=> builder.UseMaterialDynamicColors<TDynamicColorService>(_ => { });

public static MauiAppBuilder UseMaterialDynamicColors<TDynamicColorService>(this MauiAppBuilder builder, uint fallbackSeed)
public static MauiAppBuilder UseMaterialDynamicColors<
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
TDynamicColorService>
(
this MauiAppBuilder builder, uint fallbackSeed
)
where TDynamicColorService : class, IDynamicColorService
=> builder.UseMaterialDynamicColors<TDynamicColorService>(opt => opt.FallbackSeed = (int)fallbackSeed);

public static MauiAppBuilder UseMaterialDynamicColors<TDynamicColorService>(
public static MauiAppBuilder UseMaterialDynamicColors<
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
TDynamicColorService>
(
this MauiAppBuilder builder,
Action<DynamicColorOptions> configureOptions
)
Expand All @@ -32,4 +45,4 @@ Action<DynamicColorOptions> configureOptions
builder.Services.AddSingleton<IMauiInitializeService, InitializeService<TDynamicColorService>>();
return builder;
}
}
}
11 changes: 1 addition & 10 deletions Playground/Playground.Maui/Playground.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,7 @@
<ProjectReference Include="..\..\MaterialColorUtilities\MaterialColorUtilities.csproj" />
<ProjectReference Include="..\Playground.Shared\Playground.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<MauiXaml Update="Views\GraphsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\ThemePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>


<!--Configure multi-targeting (https://docs.microsoft.com/en-us/dotnet/maui/platform-integration/configure-multi-targeting#combine-filename-and-folder-multi-targeting)-->
<ItemGroup Condition="$(TargetFramework.StartsWith('net6.0-android')) != true">
<Compile Remove="**\**\*.Android.cs" />
Expand Down
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "6.0.400",
"rollForward": "latestMinor",
"allowPrerelease": true
}
}

0 comments on commit 1c1c15a

Please sign in to comment.