Skip to content

Commit

Permalink
Merge 271ad8a into 91e53ea
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-EEE authored Nov 28, 2019
2 parents 91e53ea + 271ad8a commit 4e0defd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;

namespace ExtendedXmlSerializer.ContentModel.Collections
{
sealed class MappedArraySerializers : IContents
{
readonly IContents _contents;

public MappedArraySerializers(IContents contents)
{
_contents = contents;
}
public MappedArraySerializers(IContents contents) => _contents = contents;

public ISerializer Get(TypeInfo parameter)
{
Expand Down Expand Up @@ -53,25 +50,12 @@ public void Write(IFormatWriter writer, Array instance)
}
}

sealed class SizeOf<T> : ISource<int>
sealed class SizeOf<T> : DelegatedSource<int>
{
[UsedImplicitly]
public static SizeOf<T> Default { get; } = new SizeOf<T>();

SizeOf() {}

public int Get()
{
var dm = new DynamicMethod("func", typeof(int), Type.EmptyTypes);

ILGenerator il = dm.GetILGenerator();
il.Emit(OpCodes.Sizeof, typeof(T));
il.Emit(OpCodes.Ret);

var factory = (Func<int>)dm.CreateDelegate(typeof(Func<int>));
var result = factory();
return result;
}
SizeOf() : base(Unsafe.SizeOf<T>) {}
}

sealed class Sizes : StructureCache<TypeInfo, int>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
using System.Reflection;
using ExtendedXmlSerializer.Core.Specifications;
using ExtendedXmlSerializer.ReflectionModel;

namespace ExtendedXmlSerializer.ContentModel.Collections
{
sealed class MappedArraySpecification : ISpecification<TypeInfo>
{
public static MappedArraySpecification Default { get; } = new MappedArraySpecification();

readonly ISpecification<TypeInfo> _specification;

public MappedArraySpecification() : this(IsValueTypeSpecification.Default) {}

public MappedArraySpecification(ISpecification<TypeInfo> specification)
{
_specification = specification;
}

public bool IsSatisfiedBy(TypeInfo parameter) => parameter.GetArrayRank() > 1 &&
_specification.IsSatisfiedBy(parameter.GetElementType());
}
using System.Reflection;
using ExtendedXmlSerializer.Core.Specifications;
using ExtendedXmlSerializer.ReflectionModel;

namespace ExtendedXmlSerializer.ContentModel.Collections
{
sealed class MappedArraySpecification : ISpecification<TypeInfo>
{
public static MappedArraySpecification Default { get; } = new MappedArraySpecification();

readonly ISpecification<TypeInfo> _specification;

public MappedArraySpecification() : this(IsValueTypeSpecification.Default) {}

public MappedArraySpecification(ISpecification<TypeInfo> specification) => _specification = specification;

public bool IsSatisfiedBy(TypeInfo parameter) => parameter.GetArrayRank() > 1 &&
_specification.IsSatisfiedBy(parameter.GetElementType());
}
}
2 changes: 1 addition & 1 deletion src/ExtendedXmlSerializer/ExtendedXmlSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<PackageReference Include="NReco.LambdaParser" Version="1.0.10" />
<PackageReference Include="Sprache" Version="2.2.0" />
<PackageReference Include="System.Interactive" Version="4.0.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.6.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
</ItemGroup>
</Project>

0 comments on commit 4e0defd

Please sign in to comment.