Skip to content

Commit

Permalink
added netstandard2.0 target to reduce dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Doraku committed Sep 10, 2018
1 parent 1d68391 commit 48d88d1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,10 @@ DefaultEcs support serialization to save and load a World state. Two implementat
- IComponentTypeReader is used to get the settings of the serialized World in case a maxComponentCount has been set for a specific type different from the maxEntityCount
- IComponentReader is used to get all the components of an Entity

The provided implementation TextSerializer and BinarySerializer are still in development and do not support serialization of types without a default constructor.
Nonetheless both are highly permissive and will serialize every fields and properties even if the are private or readonly and do not require any attribute decoration to work.
The provided implementation TextSerializer and BinarySerializer are highly permissive and will serialize every fields and properties even if the are private or readonly and do not require any attribute decoration to work.
This was a target from the get go as graphic and framework libraries do not always have well decorated type which would be used as component.
Although the lowest target is netstandard1.1, please be aware that the capability of both implementation to handle type with no default constructor maybe not work if the version of your .NET plateform is too low.

If you have knownledge of a serialization framework which works with everything without decoration or external schema file, please tell me because serialization is pain and I should not have started this thing.

```C#
ISerializer serializer = new TextSerializer();
Expand Down
17 changes: 11 additions & 6 deletions source/DefaultEcs/DefaultEcs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Compilation">
<LangVersion>latest</LangVersion>
<TargetFramework>netstandard1.1</TargetFramework>
<TargetFrameworks>
netstandard1.1;
netstandard2.0;
</TargetFrameworks>
<Optimize>true</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Configurations>Debug;Release</Configurations>
Expand All @@ -15,13 +18,15 @@
<Optimize>false</Optimize>
<DefineConstants>DEBUG</DefineConstants>
</PropertyGroup>


<ItemGroup Label="netstandard1.1 Reference" Condition="'$(TargetFramework)'=='netstandard1.1'">
<PackageReference Include="System.Runtime" Version="4.3.0" />

<PackageReference Label="Documentation" Include="Vsxmd" Version="1.3.3" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Label="Reference">
<PackageReference Include="System.Memory" Version="4.5.1" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Runtime" Version="4.3.0" />

<PackageReference Label="Documentation" Include="Vsxmd" Version="1.3.3" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Label="Package">
Expand All @@ -38,7 +43,7 @@
<Version>0.6.1</Version>
<PackageReleaseNotes>
added RemoveFromChildrenOf and RemoveFromParentsOf methods on Entity to remove hierarchy of dispose chain
BinarySerializer and TextSerializer now handle abstract types
BinarySerializer and TextSerializer now handle abstract types and types with no default constructor
some fixes on BinarySerializer and TextSerializer
</PackageReleaseNotes>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
#if NETSTANDARD1_1
using System.Runtime.CompilerServices;
#else
using System.Runtime.Serialization;
#endif

namespace DefaultEcs.Technical.Serialization.BinarySerializer
{
Expand Down Expand Up @@ -142,7 +146,12 @@ static Converter()
{
readGenerator.Emit(
OpCodes.Call,
typeof(RuntimeHelpers).GetRuntimeMethod("GetUninitializedObject", new[] { typeof(Type) }) ?? typeof(Activator).GetRuntimeMethod(nameof(Activator.CreateInstance), new[] { typeof(Type) }));
#if NETSTANDARD1_1
typeof(RuntimeHelpers).GetRuntimeMethod("GetUninitializedObject", new[] { typeof(Type) }) ?? typeof(Activator).GetRuntimeMethod(nameof(Activator.CreateInstance), new[] { typeof(Type) })
#else
typeof(FormatterServices).GetMethod(nameof(FormatterServices.GetUninitializedObject))
#endif
);
readGenerator.Emit(OpCodes.Castclass, _type);
readGenerator.Emit(OpCodes.Stloc, readValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
#if NETSTANDARD1_1
using System.Runtime.CompilerServices;
#else
using System.Runtime.Serialization;
#endif

namespace DefaultEcs.Technical.Serialization.TextSerializer
{
Expand Down Expand Up @@ -116,10 +120,14 @@ static Converter()
}
else
{
#if NETSTANDARD1_1
MethodInfo method =
typeof(RuntimeHelpers).GetRuntimeMethod("GetUninitializedObject", new[] { typeof(Type) })
?? typeof(Activator).GetRuntimeMethod(nameof(Activator.CreateInstance), new[] { typeof(Type) });
_constructor = (Func<Type, object>)method.CreateDelegate(typeof(Func<Type, object>));
#else
_constructor = FormatterServices.GetUninitializedObject;
#endif
}

_readFieldActions = new Dictionary<string, ReadFieldAction>();
Expand Down

0 comments on commit 48d88d1

Please sign in to comment.