diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f8592ff5..a4ee07d6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,10 +25,10 @@ jobs:
run: dotnet test -c Release ValveKeyValue/ValveKeyValue.Test/ValveKeyValue.Test.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput='./lcov.info' /p:Include="[ValveKeyValue*]*"
- name: Upload test coverage
- uses: coverallsapp/github-action@v1.1.1
+ uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- path-to-lcov: ./ValveKeyValue/ValveKeyValue.Test/lcov.info
+ path-to-lcov: ./ValveKeyValue/ValveKeyValue.Test/lcov.net5.0.info
flag-name: run-${{ matrix.test_number }}
parallel: true
@@ -37,7 +37,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
- uses: coverallsapp/github-action@v1.1.1
+ uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
diff --git a/Directory.Build.props b/Directory.Build.props
index 2304ba2b..891dd95a 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -13,8 +13,6 @@
embedded
true
en
- false
- false
true
diff --git a/ValveKeyValue/ValveKeyValue.Test/ValveKeyValue.Test.csproj b/ValveKeyValue/ValveKeyValue.Test/ValveKeyValue.Test.csproj
index 8521931d..df8c9d6a 100644
--- a/ValveKeyValue/ValveKeyValue.Test/ValveKeyValue.Test.csproj
+++ b/ValveKeyValue/ValveKeyValue.Test/ValveKeyValue.Test.csproj
@@ -1,7 +1,7 @@
Exe
- netcoreapp3.1
+ netcoreapp3.1;net5.0
ValveKeyValue.Test
Valve KeyValue Library - Unit Tests
Unit Tests for library to parse and write Valve KeyValue formats
diff --git a/ValveKeyValue/ValveKeyValue/DefaultObjectReflector.cs b/ValveKeyValue/ValveKeyValue/DefaultObjectReflector.cs
index 1ed55e9a..c25c162a 100644
--- a/ValveKeyValue/ValveKeyValue/DefaultObjectReflector.cs
+++ b/ValveKeyValue/ValveKeyValue/DefaultObjectReflector.cs
@@ -1,15 +1,29 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
namespace ValveKeyValue
{
sealed class DefaultObjectReflector : IObjectReflector
{
- IEnumerable IObjectReflector.GetMembers(object @object)
+ IEnumerable IObjectReflector.GetMembers(
+#if NET5_0_OR_GREATER
+ [DynamicallyAccessedMembers(Trimming.Properties)]
+#endif
+ Type type,
+ object @object)
{
+ Require.NotNull(type, nameof(type));
Require.NotNull(@object, nameof(@object));
- var properties = @object.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+ var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+ return GetMembersFromProperties(@object, properties);
+
+ }
+
+ static IEnumerable GetMembersFromProperties(object @object, PropertyInfo[] properties)
+ {
foreach (var property in properties)
{
if (property.GetCustomAttribute() != null)
diff --git a/ValveKeyValue/ValveKeyValue/IObjectReflector.cs b/ValveKeyValue/ValveKeyValue/IObjectReflector.cs
index a03e7f7c..db4f2f16 100644
--- a/ValveKeyValue/ValveKeyValue/IObjectReflector.cs
+++ b/ValveKeyValue/ValveKeyValue/IObjectReflector.cs
@@ -1,9 +1,16 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
namespace ValveKeyValue
{
interface IObjectReflector
{
- IEnumerable GetMembers(object @object);
+ IEnumerable GetMembers(
+#if NET5_0_OR_GREATER
+ [DynamicallyAccessedMembers(Trimming.Properties)]
+#endif
+ Type type,
+ object @object);
}
}
diff --git a/ValveKeyValue/ValveKeyValue/KVSerializer.cs b/ValveKeyValue/ValveKeyValue/KVSerializer.cs
index 35c1dcd0..bdd37646 100644
--- a/ValveKeyValue/ValveKeyValue/KVSerializer.cs
+++ b/ValveKeyValue/ValveKeyValue/KVSerializer.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using ValveKeyValue.Abstraction;
using ValveKeyValue.Deserialization;
@@ -52,7 +53,11 @@ public KVObject Deserialize(Stream stream, KVSerializerOptions options = null)
/// Options to use that can influence the deserialization process.
/// A instance representing the KeyValues structure in the stream.
/// The type of object to deserialize.;
+#if NET5_0_OR_GREATER
+ public TObject Deserialize<[DynamicallyAccessedMembers(Trimming.Constructors | Trimming.Properties)] TObject>(Stream stream, KVSerializerOptions options = null)
+#else
public TObject Deserialize(Stream stream, KVSerializerOptions options = null)
+#endif
{
Require.NotNull(stream, nameof(stream));
@@ -84,7 +89,11 @@ public void Serialize(Stream stream, KVObject data, KVSerializerOptions options
/// The top-level object name
/// Options to use that can influence the serialization process.
/// The type of object to serialize.
+#if NET5_0_OR_GREATER
+ public void Serialize<[DynamicallyAccessedMembers(Trimming.Properties)] TData>(Stream stream, TData data, string name, KVSerializerOptions options = null)
+#else
public void Serialize(Stream stream, TData data, string name, KVSerializerOptions options = null)
+#endif
{
Require.NotNull(stream, nameof(stream));
diff --git a/ValveKeyValue/ValveKeyValue/ObjectCopier.cs b/ValveKeyValue/ValveKeyValue/ObjectCopier.cs
index ba5d4744..4c91fa84 100644
--- a/ValveKeyValue/ValveKeyValue/ObjectCopier.cs
+++ b/ValveKeyValue/ValveKeyValue/ObjectCopier.cs
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
@@ -12,13 +13,26 @@ namespace ValveKeyValue
// TODO: Migrate to IVisitationListener
static class ObjectCopier
{
+#if NET5_0_OR_GREATER
+ public static TObject MakeObject<[DynamicallyAccessedMembers(Trimming.Constructors | Trimming.Properties)] TObject>(KVObject keyValueObject)
+#else
public static TObject MakeObject(KVObject keyValueObject)
+#endif
=> MakeObject(keyValueObject, new DefaultObjectReflector());
- public static object MakeObject(Type objectType, KVObject keyValueObject, IObjectReflector reflector)
+ public static object MakeObject(
+#if NET5_0_OR_GREATER
+ [DynamicallyAccessedMembers(Trimming.Constructors | Trimming.Properties)]
+#endif
+ Type objectType, KVObject keyValueObject, IObjectReflector reflector)
=> InvokeGeneric(nameof(MakeObject), objectType, new object[] { keyValueObject, reflector });
+#if NET5_0_OR_GREATER
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2062", Justification = "If the lookup value type exists at runtime then it should have enough for us to introspect.")]
+ public static TObject MakeObject<[DynamicallyAccessedMembers(Trimming.Constructors | Trimming.Properties)] TObject>(KVObject keyValueObject, IObjectReflector reflector)
+#else
public static TObject MakeObject(KVObject keyValueObject, IObjectReflector reflector)
+#endif
{
Require.NotNull(keyValueObject, nameof(keyValueObject));
Require.NotNull(reflector, nameof(reflector));
@@ -60,10 +74,24 @@ public static TObject MakeObject(KVObject keyValueObject, IObjectReflec
}
}
- public static KVObject FromObject(Type objectType, object managedObject, string topLevelName)
+ public static KVObject FromObject(
+#if NET5_0_OR_GREATER
+ [DynamicallyAccessedMembers(Trimming.Properties)]
+#endif
+ Type objectType,
+ object managedObject,
+ string topLevelName)
=> FromObjectCore(objectType, managedObject, topLevelName, new DefaultObjectReflector(), new HashSet