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

Adding Linker Metadata #3038

Merged
merged 5 commits into from
Jan 4, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<PrismPackageIcon>$(MSBuildThisFileDirectory)images/prism-logo.png</PrismPackageIcon>
<PrismLicenseFile>$(MSBuildThisFileDirectory)LICENSE</PrismLicenseFile>
<LangVersion>latest</LangVersion>
<PolySharpIncludeGeneratedTypes>
System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute;
System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes;
System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute;
System.Runtime.CompilerServices.IsExternalInit;
</PolySharpIncludeGeneratedTypes>
</PropertyGroup>

<PropertyGroup>
Expand Down
23 changes: 23 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,27 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<!-- Generate the NotTrimmable.cs file -->
<Target Name="AddNotTrimmableFile" BeforeTargets="BeforeCompile" Condition=" $(IsPackable) ">
<PropertyGroup>
<!-- Define the file path -->
<NotTrimmableFilePath>$(IntermediateOutputPath)NotTrimmable.g.cs</NotTrimmableFilePath>
</PropertyGroup>

<!-- Ensure the intermediate output directory exists -->
<MakeDir Directories="$(IntermediateOutputPath)" />

<!-- Write the contents to the file -->
<WriteLinesToFile
File="$(NotTrimmableFilePath)"
Lines="[assembly: System.Reflection.AssemblyMetadata(&quot;IsTrimmable&quot;, &quot;False&quot;)]"
Overwrite="true"
Encoding="UTF-8" />

<!-- Include the generated file in the compilation -->
<ItemGroup>
<Compile Include="$(NotTrimmableFilePath)" />
</ItemGroup>
</Target>

</Project>
9 changes: 5 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project>
<ItemGroup>
<PackageVersion Include="Prism.Container.Abstractions" Version="9.0.61-pre" />
<PackageVersion Include="Prism.Container.DryIoc" Version="9.0.61-pre" />
<PackageVersion Include="Prism.Container.Unity" Version="9.0.61-pre" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="Prism.Container.Abstractions" Version="9.0.80-pre" />
<PackageVersion Include="Prism.Container.DryIoc" Version="9.0.80-pre" />
<PackageVersion Include="Prism.Container.Unity" Version="9.0.80-pre" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
<PackageVersion Include="System.Reactive" Version="6.0.0" />
<PackageVersion Include="Uno.Extensions.Markup.Generators" Version="5.0.13" />
Expand Down Expand Up @@ -81,4 +82,4 @@
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
</Project>
18 changes: 8 additions & 10 deletions src/Forms/Prism.Forms/Modularity/IModuleCatalogExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics.CodeAnalysis;

namespace Prism.Modularity
{
Expand All @@ -16,7 +14,7 @@ public static class IModuleCatalogExtensions
/// <param name="catalog">Catalog</param>
/// <param name="mode"><see cref="InitializationMode"/></param>
/// <typeparam name="T">The <see cref="IModule"/> type parameter.</typeparam>
public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, InitializationMode mode = InitializationMode.WhenAvailable)
public static IModuleCatalog AddModule<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IModuleCatalog catalog, InitializationMode mode = InitializationMode.WhenAvailable)
where T : IModule =>
catalog.AddModule<T>(typeof(T).Name, mode);

Expand All @@ -27,7 +25,7 @@ public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, Initializ
/// <param name="catalog">Catalog.</param>
/// <param name="name">Name.</param>
/// <typeparam name="T">The <see cref="IModule"/> type parameter.</typeparam>
public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, string name)
public static IModuleCatalog AddModule<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IModuleCatalog catalog, string name)
where T : IModule =>
catalog.AddModule<T>(name, InitializationMode.WhenAvailable);

Expand All @@ -39,7 +37,7 @@ public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, string na
/// <param name="name">Name.</param>
/// <param name="mode"><see cref="IModule"/>.</param>
/// <typeparam name="T">The <see cref="IModule"/> type parameter.</typeparam>
public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, string name, InitializationMode mode)
public static IModuleCatalog AddModule<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IModuleCatalog catalog, string name, InitializationMode mode)
where T : IModule =>
catalog.AddModule(new ModuleInfo(typeof(T), name, mode));

Expand All @@ -50,7 +48,7 @@ public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, string na
/// <param name="catalog">The <see cref="IModuleCatalog"/> to add the <see cref="IModule"/> to.</param>
/// <param name="dependsOn">The names of the <see cref="IModule"/>'s that should be loaded when this <see cref="IModule"/> is loaded.</param>
/// <returns>The <see cref="IModuleCatalog"/></returns>
public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, params string[] dependsOn)
public static IModuleCatalog AddModule<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IModuleCatalog catalog, params string[] dependsOn)
where T : IModule => catalog.AddModule<T>(InitializationMode.WhenAvailable, dependsOn);

/// <summary>
Expand All @@ -61,7 +59,7 @@ public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, params st
/// <param name="name">The name of the <see cref="IModule"/></param>
/// <param name="dependsOn">The names of the <see cref="IModule"/>'s that should be loaded when this <see cref="IModule"/> is loaded.</param>
/// <returns>The <see cref="IModuleCatalog"/></returns>
public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, string name, params string[] dependsOn)
public static IModuleCatalog AddModule<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IModuleCatalog catalog, string name, params string[] dependsOn)
where T : IModule =>
catalog.AddModule<T>(name, InitializationMode.WhenAvailable, dependsOn);

Expand All @@ -73,7 +71,7 @@ public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, string na
/// <param name="mode"></param>
/// <param name="dependsOn">The names of the <see cref="IModule"/>'s that should be loaded when this <see cref="IModule"/> is loaded.</param>
/// <returns>The <see cref="IModuleCatalog"/></returns>
public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, InitializationMode mode, params string[] dependsOn)
public static IModuleCatalog AddModule<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IModuleCatalog catalog, InitializationMode mode, params string[] dependsOn)
where T : IModule =>
catalog.AddModule<T>(typeof(T).Name, mode, dependsOn);

Expand All @@ -86,7 +84,7 @@ public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, Initializ
/// <param name="mode">The <see cref="InitializationMode"/></param>
/// <param name="dependsOn">The names of the <see cref="IModule"/>'s that should be loaded when this <see cref="IModule"/> is loaded.</param>
/// <returns>The <see cref="IModuleCatalog"/></returns>
public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, string name, InitializationMode mode, params string[] dependsOn)
public static IModuleCatalog AddModule<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IModuleCatalog catalog, string name, InitializationMode mode, params string[] dependsOn)
where T : IModule
{
var moduleInfo = new ModuleInfo(name, typeof(T).AssemblyQualifiedName, dependsOn)
Expand Down
4 changes: 4 additions & 0 deletions src/Forms/Prism.Forms/Prism.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Prism for Xamarin.Forms helps you more easily design and build rich, flexible, a

<ItemGroup>
<PackageReference Include="Xamarin.Forms" />
<PackageReference Include="PolySharp">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 1 addition & 3 deletions src/Forms/Prism.Forms/PrismApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected virtual void ConfigureViewModelLocator()
{
ViewModelLocationProvider.SetDefaultViewModelFactory((view, type) =>
{
List<(Type Type, object Instance)> overrides = new List<(Type, object)>();
List<(Type Type, object Instance)> overrides = [];
if (Container.IsRegistered<IResolverOverridesHelper>())
{
var resolver = Container.Resolve<IResolverOverridesHelper>();
Expand Down Expand Up @@ -148,8 +148,6 @@ protected virtual void Initialize()
PlatformInitializer?.RegisterTypes(_containerExtension);
RegisterTypes(_containerExtension);

_containerExtension.FinalizeExtension();

_moduleCatalog = Container.Resolve<IModuleCatalog>();
ConfigureModuleCatalog(_moduleCatalog);
}
Expand Down
11 changes: 6 additions & 5 deletions src/Maui/Prism.Maui/Ioc/BehaviorFactoryRegistrationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Prism.Behaviors;
using System.Diagnostics.CodeAnalysis;
using Prism.Behaviors;

namespace Prism.Ioc;

Expand Down Expand Up @@ -31,7 +32,7 @@ public static IContainerRegistry RegisterPageBehaviorFactory(this IContainerRegi
/// <typeparam name="TBehavior"></typeparam>
/// <param name="container"></param>
/// <returns></returns>
public static IContainerRegistry RegisterPageBehavior<TBehavior>(this IContainerRegistry container)
public static IContainerRegistry RegisterPageBehavior<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TBehavior>(this IContainerRegistry container)
where TBehavior : Behavior =>
container
.Register<TBehavior>()
Expand All @@ -44,7 +45,7 @@ public static IContainerRegistry RegisterPageBehavior<TBehavior>(this IContainer
/// <typeparam name="TBehavior">The type of Behavior</typeparam>
/// <param name="container"></param>
/// <returns></returns>
public static IContainerRegistry RegisterPageBehavior<TPage, TBehavior>(this IContainerRegistry container)
public static IContainerRegistry RegisterPageBehavior<TPage, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TBehavior>(this IContainerRegistry container)
where TPage : Page
where TBehavior : Behavior =>
container
Expand Down Expand Up @@ -81,7 +82,7 @@ public static IServiceCollection RegisterPageBehaviorFactory(this IServiceCollec
/// <typeparam name="TBehavior">The <see cref="Behavior"/> type.</typeparam>
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
/// <returns>The <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection RegisterPageBehavior<TBehavior>(this IServiceCollection services)
public static IServiceCollection RegisterPageBehavior<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TBehavior>(this IServiceCollection services)
where TBehavior : Behavior =>
services
.AddTransient<TBehavior>()
Expand All @@ -94,7 +95,7 @@ public static IServiceCollection RegisterPageBehavior<TBehavior>(this IServiceCo
/// <typeparam name="TBehavior">The <see cref="Behavior"/> type.</typeparam>
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
/// <returns>The <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection RegisterPageBehavior<TPage, TBehavior>(this IServiceCollection services)
public static IServiceCollection RegisterPageBehavior<TPage, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TBehavior>(this IServiceCollection services)
where TPage : Page
where TBehavior : Behavior =>
services
Expand Down
16 changes: 8 additions & 8 deletions src/Maui/Prism.Maui/Ioc/DialogRegistrationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System.Diagnostics.CodeAnalysis;
using Prism.Dialogs;
using Prism.Mvvm;

namespace Prism.Ioc;

public static class DialogRegistrationExtensions
{
public static IContainerRegistry RegisterDialog<TView>(this IContainerRegistry containerRegistry, string name = null)
public static IContainerRegistry RegisterDialog<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IContainerRegistry containerRegistry, string name = null)
where TView : View =>
containerRegistry.RegisterDialog(typeof(TView), null, name);

public static IContainerRegistry RegisterDialog<TView, TViewModel>(this IContainerRegistry containerRegistry, string name = null)
public static IContainerRegistry RegisterDialog<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry containerRegistry, string name = null)
where TView : View =>
containerRegistry.RegisterDialog(typeof(TView), typeof(TViewModel), name);

Expand All @@ -23,15 +24,15 @@ public static IContainerRegistry RegisterDialog(this IContainerRegistry containe
return container;
}

public static IContainerRegistry RegisterDialogContainer<T>(this IContainerRegistry container)
public static IContainerRegistry RegisterDialogContainer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IContainerRegistry container)
where T : class, IDialogContainer =>
container.Register<IDialogContainer, T>();

public static IServiceCollection RegisterDialog<TView>(this IServiceCollection services, string name = null)
public static IServiceCollection RegisterDialog<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IServiceCollection services, string name = null)
where TView : View =>
services.RegisterDialog(typeof(TView), null, name);

public static IServiceCollection RegisterDialog<TView, TViewModel>(this IServiceCollection services, string name = null)
public static IServiceCollection RegisterDialog<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IServiceCollection services, string name = null)
where TView : View =>
services.RegisterDialog(typeof(TView), typeof(TViewModel), name);

Expand All @@ -45,14 +46,13 @@ public static IServiceCollection RegisterDialog(this IServiceCollection services
return services;
}

public static IServiceCollection RegisterDialogContainer<T>(this IServiceCollection services)
public static IServiceCollection RegisterDialogContainer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IServiceCollection services)
where T : class, IDialogContainer =>
services.AddTransient<IDialogContainer, T>();

private static ViewRegistration GetViewRegistration(Type view, Type viewModel, string name)
{
if (view is null)
throw new ArgumentNullException(nameof(view));
ArgumentNullException.ThrowIfNull(view);

if (!view.IsAssignableTo(typeof(View)))
throw new InvalidOperationException($"The Dialog '{view.FullName}' must inherit from Microsoft.Maui.Controls.View");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Prism.Mvvm;
using System.Diagnostics.CodeAnalysis;
using Prism.Mvvm;

namespace Prism.Ioc;

Expand All @@ -10,11 +11,11 @@ public static class MicrosoftDependencyInjectionExtensions
#if !UNO_WINUI_PROJECT
private static readonly Type PageType = typeof(Page);

public static IServiceCollection RegisterForNavigation<TView>(this IServiceCollection services, string name = null)
public static IServiceCollection RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IServiceCollection services, string name = null)
where TView : Page =>
services.RegisterForNavigation(typeof(TView), null, name);

public static IServiceCollection RegisterForNavigation<TView, TViewModel>(this IServiceCollection services, string name = null)
public static IServiceCollection RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IServiceCollection services, string name = null)
where TView : Page =>
services.RegisterForNavigation(typeof(TView), typeof(TViewModel), name);

Expand Down
7 changes: 4 additions & 3 deletions src/Maui/Prism.Maui/Ioc/NavigationRegistrationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Prism.Mvvm;
using System.Diagnostics.CodeAnalysis;
using Prism.Mvvm;

namespace Prism.Ioc;

public static class NavigationRegistrationExtensions
{
public static IContainerRegistry RegisterForNavigation<TView>(this IContainerRegistry container, string name = null)
public static IContainerRegistry RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IContainerRegistry container, string name = null)
where TView : Page =>
container.RegisterForNavigation(typeof(TView), null, name);

public static IContainerRegistry RegisterForNavigation<TView, TViewModel>(this IContainerRegistry container, string name = null)
public static IContainerRegistry RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry container, string name = null)
where TView : Page =>
container.RegisterForNavigation(typeof(TView), typeof(TViewModel), name);

Expand Down
Loading
Loading