Skip to content

Commit 828f576

Browse files
committed
Fix trimming errors added in net9
1 parent 44095e6 commit 828f576

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

ValveKeyValue/ValveKeyValue/ObjectCopier.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static object MakeObject(
1919
[DynamicallyAccessedMembers(Trimming.Properties)] Type objectType, KVObject keyValueObject, IObjectReflector reflector)
2020
=> InvokeGeneric(nameof(MakeObject), objectType, new object[] { keyValueObject, reflector });
2121

22+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2062", Justification = "If the lookup value type exists at runtime then it should have enough for us to introspect.")]
2223
public static TObject MakeObject<[DynamicallyAccessedMembers(Trimming.Constructors | Trimming.Properties)] TObject>(KVObject keyValueObject, IObjectReflector reflector)
2324
{
2425
Require.NotNull(keyValueObject, nameof(keyValueObject));
@@ -46,7 +47,7 @@ public static object MakeObject(
4647
// The object must remain boxed until it is fully initiallized, as this is the only way
4748
// that we can build a struct due to the nature of struct copying.
4849
var typedObject = RuntimeHelpers.GetUninitializedObject(typeof(TObject));
49-
CopyObject(keyValueObject, typedObject, reflector);
50+
CopyObject(keyValueObject, typeof(TObject), typedObject, reflector);
5051
return (TObject)typedObject;
5152
}
5253
else if (TryConvertValueTo<TObject>(keyValueObject.Name, keyValueObject.Value, out var converted))
@@ -86,6 +87,7 @@ static KVObject FromObjectCore(
8687
return new KVObject(topLevelName, transformedValue);
8788
}
8889

90+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072", Justification = "If the IDictionary's value object already exists at runtime then its properties will too.")]
8991
static KVValue ConvertObjectToValue(
9092
[DynamicallyAccessedMembers(Trimming.Properties)] Type objectType,
9193
object managedObject,
@@ -144,7 +146,7 @@ static KVValue ConvertObjectToValue(
144146
return childObjects;
145147
}
146148

147-
static void CopyObject(KVObject kv, object obj, IObjectReflector reflector)
149+
static void CopyObject(KVObject kv, [DynamicallyAccessedMembers(Trimming.Properties)] Type objectType, object obj, IObjectReflector reflector)
148150
{
149151
Require.NotNull(kv, nameof(kv));
150152

@@ -155,7 +157,7 @@ static void CopyObject(KVObject kv, object obj, IObjectReflector reflector)
155157

156158
Require.NotNull(reflector, nameof(reflector));
157159

158-
var members = reflector.GetMembers(obj.GetType(), obj).ToDictionary(m => m.Name, m => m, StringComparer.OrdinalIgnoreCase);
160+
var members = reflector.GetMembers(objectType, obj).ToDictionary(m => m.Name, m => m, StringComparer.OrdinalIgnoreCase);
159161

160162
foreach (var item in kv.Children)
161163
{
@@ -374,8 +376,7 @@ static bool IsDictionary(Type type)
374376
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060", Justification = "Analysis cannot follow MakeGenericMethod but we should be clear by here anyway.")]
375377
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Analysis cannot follow MakeGenericMethod but we should be clear by here anyway.")]
376378
static object MakeDictionary(
377-
[DynamicallyAccessedMembers(Trimming.Constructors | Trimming.Properties)]
378-
Type type,
379+
[DynamicallyAccessedMembers(Trimming.Constructors | Trimming.Properties)] Type type,
379380
KVObject kv,
380381
IObjectReflector reflector)
381382
{

0 commit comments

Comments
 (0)