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

More AOT annotations to the code from IL2072 #4363

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions Samples/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<PropertyGroup Condition="False" Label="For local development">
<!-- Place any interesing properties here, which can simplify local loop -->
<SelfContained>true</SelfContained>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
<ItemGroup Condition="False" Label="For local development">
<PackageReference Remove="Csla" />
<ProjectReference Include="..\..\..\Source\Csla\Csla.csproj" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Samples/RuleTutorial/RuleTutorial.sln
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0FDAA019-DE44-48CD-9614-2A36E45EFCA3}"
ProjectSection(SolutionItems) = preProject
Local.testsettings = Local.testsettings
..\Directory.Build.targets = ..\Directory.Build.targets
RuleTutorial.rtf = RuleTutorial.rtf
RuleTutorial.vsmdi = RuleTutorial.vsmdi
TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
Original file line number Diff line number Diff line change
@@ -88,9 +88,9 @@ internal static void AddRequiredDataPortalServices(this CslaOptions config, ISer
services.TryAddTransient<IChildDataPortalFactory, ChildDataPortalFactory>();

services.TryAddScoped(typeof(IAuthorizeDataPortal), config.DataPortalOptions.DataPortalServerOptions.AuthorizerProviderType);
foreach (Type interceptorType in config.DataPortalOptions.DataPortalServerOptions.InterceptorProviders)
foreach (var interceptorType in config.DataPortalOptions.DataPortalServerOptions.InterceptorProviders)
{
services.AddScoped(typeof(IInterceptDataPortal), interceptorType);
services.AddScoped(typeof(IInterceptDataPortal), interceptorType.type);
}
services.TryAddScoped(typeof(IObjectFactoryLoader), config.DataPortalOptions.DataPortalServerOptions.ObjectFactoryLoaderType);
services.TryAddScoped(typeof(IDataPortalActivator), config.DataPortalOptions.DataPortalServerOptions.ActivatorType);
35 changes: 30 additions & 5 deletions Source/Csla/Configuration/Fluent/DataPortalServerOptions.cs
Original file line number Diff line number Diff line change
@@ -78,15 +78,19 @@ public DataPortalServerOptions RegisterAuthorizerProvider<
/// that should be executed by the server-side data portal.
/// injection.
/// </summary>
internal List<Type> InterceptorProviders { get; } = [typeof(Server.Interceptors.ServerSide.RevalidatingInterceptor)];
internal List<ActivatableType> InterceptorProviders { get; } = [new(typeof(Server.Interceptors.ServerSide.RevalidatingInterceptor))];

/// <summary>
/// Adds the type of an IInterceptDataPortal that will
/// be executed by the server-side data portal.
/// </summary>
public DataPortalServerOptions AddInterceptorProvider<T>() where T: IInterceptDataPortal
public DataPortalServerOptions AddInterceptorProvider<
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>() where T: IInterceptDataPortal
{
InterceptorProviders.Add(typeof(T));
InterceptorProviders.Add(new(typeof(T)));
return this;
}

@@ -95,9 +99,13 @@ public DataPortalServerOptions AddInterceptorProvider<T>() where T: IInterceptDa
/// be executed by the server-side data portal.
/// </summary>
/// <param name="index">Index at which new item should be added.</param>
public DataPortalServerOptions AddInterceptorProvider<T>(int index) where T : IInterceptDataPortal
public DataPortalServerOptions AddInterceptorProvider<
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>(int index) where T : IInterceptDataPortal
{
InterceptorProviders.Insert(index, typeof(T));
InterceptorProviders.Insert(index, new(typeof(T)));
return this;
}

@@ -191,4 +199,21 @@ public DataPortalServerOptions RegisterObjectFactoryLoader<
/// </summary>
public bool DataPortalReturnObjectOnException { get; set; } = false;
}
struct ActivatableType
{
public ActivatableType(
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
Type type)
{
this.type = type;
}

#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
public Type type;
}

}
26 changes: 21 additions & 5 deletions Source/Csla/Core/FieldManager/FieldDataManager.cs
Original file line number Diff line number Diff line change
@@ -195,18 +195,18 @@ private static List<IPropertyInfo> CreateConsolidatedList(
List<IPropertyInfo> result = [];

// get inheritance hierarchy
Type current = type;
List<Type> hierarchy = [];
AllMembersType current = new(type);
List<AllMembersType> hierarchy = [];
do
{
hierarchy.Add(current);
current = current.BaseType;
} while (current != null && !current.Equals(typeof(BusinessBase)));
current = new (current.type.BaseType);
} while (current.type != null && !current.Equals(typeof(BusinessBase)));

// walk from top to bottom to build consolidated list
for (int index = hierarchy.Count - 1; index >= 0; index--)
{
var source = PropertyInfoManager.GetPropertyListCache(hierarchy[index]);
var source = PropertyInfoManager.GetPropertyListCache(hierarchy[index].type);
source.IsLocked = true;
result.AddRange(source);
}
@@ -891,4 +891,20 @@ private static void OnAssemblyLoadContextUnload(AssemblyLoadContext context)
}
#endif
}
struct AllMembersType
{
public AllMembersType(
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
#endif
Type type)
{
this.type = type;
}

#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
#endif
public Type type;
}
}
4 changes: 2 additions & 2 deletions Source/Csla/DataPortalClient/DataPortalFactory.cs
Original file line number Diff line number Diff line change
@@ -33,9 +33,9 @@ public DataPortalFactory(IServiceProvider serviceProvider)
/// <typeparam name="T">Root business object type</typeparam>
public IDataPortal<T> GetPortal<
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>()
T>()
{
return (IDataPortal<T>)ServiceProvider.GetService(typeof(IDataPortal<T>));
}
8 changes: 7 additions & 1 deletion Source/Csla/IChildDataPortalFactory.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
// </copyright>
// <summary>Implements a data portal service</summary>
//-----------------------------------------------------------------------
using System.Diagnostics.CodeAnalysis;

namespace Csla
{
/// <summary>
@@ -18,6 +20,10 @@ public interface IChildDataPortalFactory
/// Get a child data portal instance.
/// </summary>
/// <typeparam name="T">Child business object type</typeparam>
IChildDataPortal<T> GetPortal<T>();
IChildDataPortal<T> GetPortal<
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>();
}
}
8 changes: 7 additions & 1 deletion Source/Csla/IChildDataPortalT.cs
Original file line number Diff line number Diff line change
@@ -6,13 +6,19 @@
// <summary>Interface defining the members of the child data portal type</summary>
//-----------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;

namespace Csla
{
/// <summary>
/// Interface defining the members of the child data portal type.
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IChildDataPortal<T>
public interface IChildDataPortal<
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>
{
/// <summary>
/// Starts an asynchronous data portal operation to
2 changes: 1 addition & 1 deletion Source/Csla/IDataPortalFactory.cs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ public interface IDataPortalFactory
/// <typeparam name="T">Root business object type</typeparam>
IDataPortal<T> GetPortal<
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>();
}
2 changes: 1 addition & 1 deletion Source/Csla/IDataPortalT.cs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ namespace Csla
public interface IDataPortal<
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
# endif
#endif
T>
{
/// <summary>
8 changes: 7 additions & 1 deletion Source/Csla/Server/ChildDataPortalFactory.cs
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@
// <summary>Implements a data portal service</summary>
//-----------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;

namespace Csla.Server
{
/// <summary>
@@ -29,7 +31,11 @@ public ChildDataPortalFactory(IServiceProvider serviceProvider)
/// Get a client-side data portal instance.
/// </summary>
/// <typeparam name="T">Root business object type</typeparam>
public IChildDataPortal<T> GetPortal<T>()
public IChildDataPortal<T> GetPortal<
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>()
{
return (IChildDataPortal<T>)ServiceProvider.GetService(typeof(IChildDataPortal<T>));
}
5 changes: 5 additions & 0 deletions Source/Csla/Server/IObjectFactoryLoader.cs
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@
// <summary>Defines an interface to be implemented by</summary>
//-----------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;

namespace Csla.Server
{
/// <summary>
@@ -23,6 +25,9 @@ public interface IObjectFactoryLoader
/// Name of the factory to create, typically
/// an assembly qualified type name.
/// </param>
#if NET8_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
#endif
Type GetFactoryType(string factoryName);
/// <summary>
/// Returns an ObjectFactory object.
7 changes: 7 additions & 0 deletions Source/Csla/Server/ObjectFactoryLoader.cs
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
// <summary>Class containing the default implementation for</summary>
//-----------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;
using Csla.Properties;

namespace Csla.Server
@@ -14,6 +15,9 @@ namespace Csla.Server
/// Class containing the default implementation for
/// the FactoryLoader delegate used by the data portal host.
/// </summary>
#if NET8_0_OR_GREATER
[RequiresUnreferencedCode("The factory type with moniker factoryName cannot be statically guessed, and can be trimmed")]
#endif
public class ObjectFactoryLoader : IObjectFactoryLoader
{
/// <summary>
@@ -36,6 +40,9 @@ public ObjectFactoryLoader(ApplicationContext applicationContext)
/// the ObjectFactory attribute
/// on the business object.
/// </param>
#if NET8_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
#endif
public Type GetFactoryType(string factoryName)
{
return Type.GetType(factoryName);
16 changes: 14 additions & 2 deletions Source/Csla/Utilities.cs
Original file line number Diff line number Diff line change
@@ -74,7 +74,15 @@ public static object CallByName(
/// </summary>
/// <param name="propertyType">Type of the
/// property as returned by reflection.</param>
public static Type GetPropertyType(Type propertyType)

#if NET8_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
#endif
public static Type GetPropertyType(
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
#endif
Type propertyType)
{
Type type = propertyType;
if (type.IsGenericType &&
@@ -88,7 +96,11 @@ public static Type GetPropertyType(Type propertyType)
/// contained in a collection or list.
/// </summary>
/// <param name="listType">Type of the list.</param>
public static Type GetChildItemType(Type listType)
public static Type GetChildItemType(
#if NET8_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
#endif
Type listType)
{
Type result = null;
if (listType.IsArray)