Skip to content

Commit 2d08dcc

Browse files
Fix property setter dynamic accessing issues when PublishTrimmed is enabled in TransformSequence<T>
1 parent a5c900c commit 2d08dcc

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@
2323

2424
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2525
<GenerateDocumentationFile>true</GenerateDocumentationFile>
26+
2627
<NoWarn>CS1591, NU5104</NoWarn>
28+
29+
<!--
30+
This supresses where generic arguments don't satisfy other attributes.
31+
Occurs when publishing an app with <PublishTrimmed>true</PublishTrimmed>.
32+
-->
33+
<NoWarn>$(NoWarn);IL2091</NoWarn>
2734
</PropertyGroup>
2835

2936
<ItemGroup>

Natsu/Mathematics/Transforms/TransformSequence.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Reflection;
23

34
namespace Natsu.Mathematics.Transforms;
45

5-
public class TransformSequence<T>(T target) : ITransformSequence<T> {
6+
public class TransformSequence<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(T target) : ITransformSequence<T> {
67
/// <summary>
78
/// Returns the end time of the sequence.
89
/// </summary>
@@ -76,7 +77,6 @@ public void ResetTo(float toTime, int startIndex = 0, int endIndex = -1) {
7677
}
7778

7879
transform.DoReset?.Invoke();
79-
Console.WriteLine("Resetting " + transform.Name);
8080
} else if (transform.StartTime < toTime && transform.StartTime + transform.Duration >= toTime) {
8181
float progress = (toTime - transform.StartTime) / transform.Duration;
8282
transform.Reset(false);
@@ -118,8 +118,8 @@ public TransformSequence<T> Append(ITransform transform, bool applyBaseTime = tr
118118
/// <param name="name">The name of the transform for identification</param>
119119
/// <param name="interpolation">The interpolation function to use</param>
120120
/// <returns>The created sequence</returns>
121-
public TransformSequence<T> Create<X>(string property, X to, float duration, Easing easing, string? name, Func<X, X, float, X> interpolation) {
122-
PropertyInfo? propertyInfo = typeof(T).GetProperty(property);
121+
public TransformSequence<T> Create<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] X>(string property, X to, float duration, Easing easing, string? name, Func<X, X, float, X> interpolation) {
122+
PropertyInfo? propertyInfo = typeof(T).GetProperty(property, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
123123
if (propertyInfo == null) throw new InvalidOperationException($"Property {property} does not exist in {typeof(T).Name}");
124124

125125
X a = FutureData.TryGetValue(property, out object? value) ? (X)value : (X)propertyInfo.GetValue(Target)!;
@@ -148,7 +148,7 @@ public TransformSequence<T> Create<X>(string property, X to, float duration, Eas
148148
/// <param name="easing">The easing to apply to the time</param>
149149
/// <param name="name">The name of the transform for identification</param>
150150
/// <returns>The created sequence</returns>
151-
public TransformSequence<T> Create<X>(string property, X to, float duration, Easing easing = Easing.Linear, string? name = null) => Create(property, to, duration, easing, name, EasingHelper.GetInterpolation<X>());
151+
public TransformSequence<T> Create<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] X>(string property, X to, float duration, Easing easing = Easing.Linear, string? name = null) => Create(property, to, duration, easing, name, EasingHelper.GetInterpolation<X>());
152152

153153
/// <summary>
154154
/// Moves the <see cref="BaseTime" /> of the sequence to the end of the longest transform.

0 commit comments

Comments
 (0)