This commit is contained in:
neuecc 2017-02-26 14:35:45 +09:00
Родитель 50c34d12f0
Коммит 3f306eca78
41 изменённых файлов: 1121 добавлений и 128 удалений

Просмотреть файл

@ -15,6 +15,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T4Templates", "src\T4Templa
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{344DC89D-8761-4552-A70A-B34DC19F39C4}"
ProjectSection(SolutionItems) = preProject
nuget\MessagePack.ImmutableCollections.nuspec = nuget\MessagePack.ImmutableCollections.nuspec
nuget\MessagePack.nuspec = nuget\MessagePack.nuspec
nuget\MessagePack.ReactiveProperty.nuspec = nuget\MessagePack.ReactiveProperty.nuspec
nuget\MessagePack.UnityShims.nuspec = nuget\MessagePack.UnityShims.nuspec
nuget\pack.bat = nuget\pack.bat
nuget\push.bat = nuget\push.bat
README.md = README.md
EndProjectSection
EndProject

Просмотреть файл

@ -1,11 +1,24 @@
MessagePack for C#(.NET, .NET Core, Unity)
===
Brainchild of [ZeroFormatter](https://github.com/neuecc/ZeroFormatter/), fastest MessagePack serializer on .NET.
Work in progress, stay tuned.
![image](https://cloud.githubusercontent.com/assets/46207/23091755/aa951d5a-f600-11e6-933a-00ac768ed845.png)
![image](https://cloud.githubusercontent.com/assets/46207/23126535/65564726-f7ba-11e6-8e8e-07b249be798c.png)
![image](https://cloud.githubusercontent.com/assets/46207/23337257/9bf22222-fc2a-11e6-888f-20d0451a526e.png)
Extremely fast, x10~20 faster than MsgPack-Cli.
Work in progress, stay tuned.
Beta is relased(please enable include pre-release package).
Standard library.
```
Install-Package MessagePack
```
Extension supports.
```
Install-Package MessagePack.ImmutableCollections
Install-Package MessagePack.ReactiveProperty
Install-Package MessagePack.Unity
```

Просмотреть файл

@ -0,0 +1,35 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MessagePack.ImmutableCollection</id>
<version>0.1.0-beta</version>
<title>MessagePack for C# Extension Support for ImmutableCollection</title>
<authors>neuecc</authors>
<owners>neuecc</owners>
<projectUrl>https://github.com/neuecc/MessagePack-CSharp/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity). Extension support for System.Collections.Immutable.</description>
<releaseNotes>initial alpha.</releaseNotes>
<tags>MsgPack, MessagePack, Serialization, Formatter, Serializer</tags>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System" targetFramework=".NETFramework4.5" />
<frameworkAssembly assemblyName="System.Core" targetFramework=".NETFramework4.5" />
</frameworkAssemblies>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="MessagePack" version="0.0.1" />
<dependency id="System.Collections.Immutable" version="1.3.1" />
</group>
<group targetFramework=".NETStandard1.4">
<dependency id="MessagePack" version="0.0.1" />
<dependency id="System.Collections.Immutable" version="1.3.1" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\src\MessagePack.ImmutableCollections\bin\Release\netstandard1.4\MessagePack.ImmutableCollections.dll" target="lib\net45" />
<file src="..\src\MessagePack.ImmutableCollections\bin\Release\netstandard1.4\MessagePack.ImmutableCollections.xml" target="lib\net45" />
<file src="..\src\MessagePack.ImmutableCollections\bin\Release\netstandard1.4\MessagePack.ImmutableCollections.dll" target="lib\netstandard1.4" />
<file src="..\src\MessagePack.ImmutableCollections\bin\Release\netstandard1.4\MessagePack.ImmutableCollections.xml" target="lib\netstandard1.4" />
</files>
</package>

Просмотреть файл

@ -0,0 +1,35 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MessagePack.ReactiveProperty</id>
<version>0.1.0-beta</version>
<title>MessagePack for C# Extension Support for ReactiveProperty</title>
<authors>neuecc</authors>
<owners>neuecc</owners>
<projectUrl>https://github.com/neuecc/MessagePack-CSharp/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity). Extension support for ReactiveProperty.</description>
<releaseNotes>initial alpha.</releaseNotes>
<tags>MsgPack, MessagePack, Serialization, Formatter, Serializer, ReactiveProperty</tags>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System" targetFramework=".NETFramework4.5" />
<frameworkAssembly assemblyName="System.Core" targetFramework=".NETFramework4.5" />
</frameworkAssemblies>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="MessagePack" version="0.0.1" />
<dependency id="ReactiveProperty" version="3.5.0" />
</group>
<group targetFramework=".NETStandard1.4">
<dependency id="MessagePack" version="0.0.1" />
<dependency id="ReactiveProperty" version="3.5.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\src\MessagePack.ReactiveProperty\bin\Release\netstandard1.4\MessagePack.ReactiveProperty.dll" target="lib\net45" />
<file src="..\src\MessagePack.ReactiveProperty\bin\Release\netstandard1.4\MessagePack.ReactiveProperty.xml" target="lib\net45" />
<file src="..\src\MessagePack.ReactiveProperty\bin\Release\netstandard1.4\MessagePack.ReactiveProperty.dll" target="lib\netstandard1.4" />
<file src="..\src\MessagePack.ReactiveProperty\bin\Release\netstandard1.4\MessagePack.ReactiveProperty.xml" target="lib\netstandard1.4" />
</files>
</package>

Просмотреть файл

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MessagePack.Unity</id>
<version>0.1.0-beta</version>
<title>MessagePack for C# Extension Support for Unity(add pseudo Vector type and fast Vectory[] extension formatter)</title>
<authors>neuecc</authors>
<owners>neuecc</owners>
<projectUrl>https://github.com/neuecc/MessagePack-CSharp/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity). Extension support for Unity.</description>
<releaseNotes>initial alpha.</releaseNotes>
<tags>MsgPack, MessagePack, Serialization, Formatter, Serializer, ReactiveProperty</tags>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System" targetFramework=".NETFramework4.5" />
<frameworkAssembly assemblyName="System.Core" targetFramework=".NETFramework4.5" />
</frameworkAssemblies>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="MessagePack" version="0.0.1" />
</group>
<group targetFramework=".NETStandard1.4">
<dependency id="MessagePack" version="0.0.1" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\src\MessagePack.UnityShims\bin\Release\netstandard1.4\MessagePack.UnityShims.dll" target="lib\net45" />
<file src="..\src\MessagePack.UnityShims\bin\Release\netstandard1.4\MessagePack.UnityShims.xml" target="lib\net45" />
<file src="..\src\MessagePack.UnityShims\bin\Release\netstandard1.4\MessagePack.UnityShims.dll" target="lib\netstandard1.4" />
<file src="..\src\MessagePack.UnityShims\bin\Release\netstandard1.4\MessagePack.UnityShims.xml" target="lib\netstandard1.4" />
</files>
</package>

37
nuget/MessagePack.nuspec Normal file
Просмотреть файл

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MessagePack</id>
<version>0.1.0-beta</version>
<title>MessagePack for C#</title>
<authors>neuecc</authors>
<owners>neuecc</owners>
<projectUrl>https://github.com/neuecc/MessagePack-CSharp/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity).</description>
<releaseNotes>initial alpha.</releaseNotes>
<tags>MsgPack, MessagePack, Serialization, Formatter, Serializer</tags>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System" targetFramework=".NETFramework4.5" />
<frameworkAssembly assemblyName="System.Core" targetFramework=".NETFramework4.5" />
</frameworkAssemblies>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="System.Reflection.Emit" version="4.3.0" />
<dependency id="System.ValueTuple" version="4.3.0" />
<dependency id="System.Threading.Tasks.Extensions" version="4.3.0" />
</group>
<group targetFramework=".NETStandard1.4">
<dependency id="System.Reflection.Emit" version="4.3.0" />
<dependency id="System.ValueTuple" version="4.3.0" />
<dependency id="System.Threading.Tasks.Extensions" version="4.3.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\src\MessagePack\bin\Release\netstandard1.4\MessagePack.dll" target="lib\net45" />
<file src="..\src\MessagePack\bin\Release\netstandard1.4\MessagePack.xml" target="lib\net45" />
<file src="..\src\MessagePack\bin\Release\netstandard1.4\MessagePack.dll" target="lib\netstandard1.4" />
<file src="..\src\MessagePack\bin\Release\netstandard1.4\MessagePack.xml" target="lib\netstandard1.4" />
</files>
</package>

4
nuget/pack.bat Normal file
Просмотреть файл

@ -0,0 +1,4 @@
nuget pack MessagePack.nuspec
nuget pack MessagePack.ImmutableCollections.nuspec
nuget pack MessagePack.ReactiveProperty.nuspec
nuget pack MessagePack.UnityShims.nuspec

4
nuget/push.bat Normal file
Просмотреть файл

@ -0,0 +1,4 @@
nuget push MessagePack.0.1.0-beta.nupkg -Source https://www.nuget.org/api/v2/package
nuget push MessagePack.ImmutableCollections.0.1.0-beta.nupkg -Source https://www.nuget.org/api/v2/package
nuget push MessagePack.ReactiveProperty.0.1.0-beta.nupkg -Source https://www.nuget.org/api/v2/package
nuget push MessagePack.UnityShims.0.1.0-beta.nupkg -Source https://www.nuget.org/api/v2/package

Просмотреть файл

@ -180,15 +180,14 @@ namespace Sandbox
};
Person[] l = Enumerable.Range(1, 100).Select(x => new Person { Age = x, FirstName = "Windows", LastName = "Server", Sex = Sex.Female }).ToArray();
//Benchmark(p);
//Console.WriteLine();
//Benchmark(l);
Benchmark(p);
Console.WriteLine();
Benchmark(l);
//var json = MessagePackSerializer.ToJson(MessagePackSerializer.NonGeneric.Serialize(typeof(Person), p));
//Console.WriteLine(json);
var a = MessagePackSerializer.ToJson(new GenericClass<int, string>() { MyProperty0 = 99, MyProperty1 = "hoge" });
Console.WriteLine(a);
}
@ -237,11 +236,16 @@ namespace Sandbox
using (var ms = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(ms, target);
data2 = ms.ToArray();
}
}
}
using (var ms = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(ms, target);
data2 = ms.ToArray();
}
msgpack.GetSerializer<T>().UnpackSingleObject(data);
MessagePack.MessagePackSerializer.Deserialize<T>(data0);
ZeroFormatterSerializer.Deserialize<T>(data1);
@ -284,6 +288,53 @@ namespace Sandbox
}
}
}
Console.WriteLine();
Console.WriteLine("FileSize::");
var label = "";
label = "MsgPack-Cli"; Console.WriteLine($"{label,20} {data.Length} Byte");
label = "MessagePack-CSharp"; Console.WriteLine($"{label,20} {data0.Length} Byte");
label = "ZeroFormatter"; Console.WriteLine($"{label,20} {data1.Length} Byte");
label = "protobuf-net"; Console.WriteLine($"{label,20} {data2.Length} Byte");
Console.WriteLine();
Console.WriteLine();
}
static string ToHumanReadableSize(long size)
{
return ToHumanReadableSize(new Nullable<long>(size));
}
static string ToHumanReadableSize(long? size)
{
if (size == null) return "NULL";
double bytes = size.Value;
if (bytes <= 1024) return bytes.ToString("f2") + " B";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " KB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " MB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " GB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " TB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " PB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " EB";
bytes = bytes / 1024;
return bytes + " ZB";
}
}
@ -311,7 +362,6 @@ namespace Sandbox
// design concept sketch of Union.
[MessagePack.Union(0, typeof(HogeMoge1))]

Просмотреть файл

@ -358,4 +358,13 @@ namespace SharedData
[Key(1)]
public T2 MyProperty1 { get; set; }
}
[MessagePackObject]
public struct GenericStruct<T1, T2>
{
[Key(0)]
public T1 MyProperty0 { get; set; }
[Key(1)]
public T2 MyProperty1 { get; set; }
}
}

Просмотреть файл

@ -57,7 +57,7 @@ namespace MessagePack.ImmutableCollections
}
}
public class ImmutableListFormatter<T> : SequneceFormatterBase<T, ImmutableList<T>.Builder, ImmutableList<T>.Enumerator, ImmutableList<T>>
public class ImmutableListFormatter<T> : CollectionFormatterBase<T, ImmutableList<T>.Builder, ImmutableList<T>.Enumerator, ImmutableList<T>>
{
protected override void Add(ImmutableList<T>.Builder collection, int index, T value)
{
@ -103,7 +103,7 @@ namespace MessagePack.ImmutableCollections
}
}
public class ImmutableHashSetFormatter<T> : SequneceFormatterBase<T, ImmutableHashSet<T>.Builder, ImmutableHashSet<T>.Enumerator, ImmutableHashSet<T>>
public class ImmutableHashSetFormatter<T> : CollectionFormatterBase<T, ImmutableHashSet<T>.Builder, ImmutableHashSet<T>.Enumerator, ImmutableHashSet<T>>
{
protected override void Add(ImmutableHashSet<T>.Builder collection, int index, T value)
{
@ -149,31 +149,31 @@ namespace MessagePack.ImmutableCollections
}
}
public class ImmutableSortedSetFormatter<T> : SequneceFormatterBase<T, ImmutableSortedSet<T>.Builder, ImmutableSortedSet<T>.Enumerator, ImmutableSortedSet<T>>
public class ImmutableSortedSetFormatter<T> : CollectionFormatterBase<T, ImmutableSortedSet<T>.Builder, ImmutableSortedSet<T>.Enumerator, ImmutableSortedSet<T>>
{
protected override void Add(ImmutableSortedSet<T>.Builder collection, int index, T value)
{
throw new NotImplementedException();
collection.Add(value);
}
protected override ImmutableSortedSet<T> Complete(ImmutableSortedSet<T>.Builder intermediateCollection)
{
throw new NotImplementedException();
return intermediateCollection.ToImmutable();
}
protected override ImmutableSortedSet<T>.Builder Create(int count)
{
throw new NotImplementedException();
return ImmutableSortedSet.CreateBuilder<T>();
}
protected override ImmutableSortedSet<T>.Enumerator GetSourceEnumerator(ImmutableSortedSet<T> source)
{
throw new NotImplementedException();
return source.GetEnumerator();
}
}
// not best for performance(does not use ImmutableQueue<T>.Enumerator)
public class ImmutableQueueFormatter<T> : SequneceFormatterBase<T, ImmutableQueueBuilder<T>, ImmutableQueue<T>>
public class ImmutableQueueFormatter<T> : CollectionFormatterBase<T, ImmutableQueueBuilder<T>, ImmutableQueue<T>>
{
protected override void Add(ImmutableQueueBuilder<T> collection, int index, T value)
{
@ -192,25 +192,25 @@ namespace MessagePack.ImmutableCollections
}
// not best for performance(does not use ImmutableQueue<T>.Enumerator)
public class ImmutableStackFormatter<T> : SequneceFormatterBase<T, ImmutableStackBuilder<T>, ImmutableStack<T>>
public class ImmutableStackFormatter<T> : CollectionFormatterBase<T, T[], ImmutableStack<T>>
{
protected override void Add(ImmutableStackBuilder<T> collection, int index, T value)
protected override void Add(T[] collection, int index, T value)
{
collection.Add(value);
collection[collection.Length - 1 - index] = value;
}
protected override ImmutableStack<T> Complete(ImmutableStackBuilder<T> intermediateCollection)
protected override ImmutableStack<T> Complete(T[] intermediateCollection)
{
return intermediateCollection.stack;
return ImmutableStack.CreateRange(intermediateCollection);
}
protected override ImmutableStackBuilder<T> Create(int count)
protected override T[] Create(int count)
{
return new ImmutableStackBuilder<T>();
return new T[count];
}
}
public class InterfaceImmutableListFormatter<T> : SequneceFormatterBase<T, ImmutableList<T>.Builder, IImmutableList<T>>
public class InterfaceImmutableListFormatter<T> : CollectionFormatterBase<T, ImmutableList<T>.Builder, IImmutableList<T>>
{
protected override void Add(ImmutableList<T>.Builder collection, int index, T value)
{
@ -246,7 +246,7 @@ namespace MessagePack.ImmutableCollections
}
}
public class InterfaceImmutableSetFormatter<T> : SequneceFormatterBase<T, ImmutableHashSet<T>.Builder, IImmutableSet<T>>
public class InterfaceImmutableSetFormatter<T> : CollectionFormatterBase<T, ImmutableHashSet<T>.Builder, IImmutableSet<T>>
{
protected override void Add(ImmutableHashSet<T>.Builder collection, int index, T value)
{
@ -264,7 +264,7 @@ namespace MessagePack.ImmutableCollections
}
}
public class InterfaceImmutableQueueFormatter<T> : SequneceFormatterBase<T, ImmutableQueueBuilder<T>, IImmutableQueue<T>>
public class InterfaceImmutableQueueFormatter<T> : CollectionFormatterBase<T, ImmutableQueueBuilder<T>, IImmutableQueue<T>>
{
protected override void Add(ImmutableQueueBuilder<T> collection, int index, T value)
{
@ -282,24 +282,25 @@ namespace MessagePack.ImmutableCollections
}
}
public class InterfaceImmutableStackFormatter<T> : SequneceFormatterBase<T, ImmutableStackBuilder<T>, IImmutableStack<T>>
public class InterfaceImmutableStackFormatter<T> : CollectionFormatterBase<T, T[], IImmutableStack<T>>
{
protected override void Add(ImmutableStackBuilder<T> collection, int index, T value)
protected override void Add(T[] collection, int index, T value)
{
collection.Add(value);
collection[collection.Length - 1 - index] = value;
}
protected override IImmutableStack<T> Complete(ImmutableStackBuilder<T> intermediateCollection)
protected override IImmutableStack<T> Complete(T[] intermediateCollection)
{
return intermediateCollection.stack;
return ImmutableStack.CreateRange(intermediateCollection);
}
protected override ImmutableStackBuilder<T> Create(int count)
protected override T[] Create(int count)
{
return new ImmutableStackBuilder<T>();
return new T[count];
}
}
// pseudo builders
public class ImmutableQueueBuilder<T>
@ -311,14 +312,4 @@ namespace MessagePack.ImmutableCollections
q = q.Enqueue(value);
}
}
public class ImmutableStackBuilder<T>
{
public ImmutableStack<T> stack = ImmutableStack<T>.Empty;
public void Add(T value)
{
stack = stack.Push(value);
}
}
}

Просмотреть файл

@ -54,10 +54,22 @@ namespace MessagePack.ImmutableCollections
{
var ti = t.GetTypeInfo();
Type formatterType;
if (formatterMap.TryGetValue(t, out formatterType))
if (ti.IsGenericType)
{
return CreateInstance(formatterType, ti.GenericTypeArguments);
var genericType = ti.GetGenericTypeDefinition();
var genericTypeInfo = genericType.GetTypeInfo();
var isNullable = genericTypeInfo.IsNullable();
var nullableElementType = isNullable ? ti.GenericTypeArguments[0] : null;
Type formatterType;
if (formatterMap.TryGetValue(genericType, out formatterType))
{
return CreateInstance(formatterType, ti.GenericTypeArguments);
}
else if (isNullable && nullableElementType.IsConstructedGenericType && nullableElementType.GetGenericTypeDefinition() == typeof(ImmutableArray<>))
{
return CreateInstance(typeof(NullableFormatter<>), new[] { nullableElementType });
}
}
return null;
@ -68,4 +80,12 @@ namespace MessagePack.ImmutableCollections
return Activator.CreateInstance(genericType.MakeGenericType(genericTypeArguments), arguments);
}
}
internal static class ReflectionExtensions
{
public static bool IsNullable(this System.Reflection.TypeInfo type)
{
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Nullable<>);
}
}
}

Просмотреть файл

@ -4,6 +4,11 @@
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.4\MessagePack.ImmutableCollections.xml</DocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
</ItemGroup>

Просмотреть файл

@ -11,26 +11,30 @@ namespace MessagePack.ReactivePropertyExtension
{
#pragma warning disable CS0618
// default map
static Dictionary<int, IScheduler> mapTo = new Dictionary<int, IScheduler>
{
{-1, UIDispatcherScheduler.Default },
{-2, CurrentThreadScheduler.Instance },
{-3, ImmediateScheduler.Instance },
{-4, TaskPoolScheduler.Default },
{-5, System.Reactive.Concurrency.NewThreadScheduler.Default },
{-6, Scheduler.ThreadPool },
};
static Dictionary<int, IScheduler> mapTo = new Dictionary<int, IScheduler>();
static Dictionary<IScheduler, int> mapFrom = new Dictionary<IScheduler, int>();
static Dictionary<IScheduler, int> mapFrom = new Dictionary<IScheduler, int>
static ReactivePropertySchedulerMapper()
{
{UIDispatcherScheduler.Default,-1 },
{CurrentThreadScheduler.Instance,-2 },
{ImmediateScheduler.Instance,-3 },
{TaskPoolScheduler.Default, -4 },
{System.Reactive.Concurrency.NewThreadScheduler.Default, -5},
{Scheduler.ThreadPool, -6 }
};
// default map
var mappings = new[]
{
(-2, CurrentThreadScheduler.Instance ),
(-3, ImmediateScheduler.Instance ),
(-4, TaskPoolScheduler.Default ),
(-5, System.Reactive.Concurrency.NewThreadScheduler.Default ),
(-6, Scheduler.ThreadPool ),
(-7, System.Reactive.Concurrency.DefaultScheduler.Instance),
(-1, UIDispatcherScheduler.Default ), // override
};
foreach (var item in mappings)
{
ReactivePropertySchedulerMapper.mapTo[item.Item1] = item.Item2;
ReactivePropertySchedulerMapper.mapFrom[item.Item2] = item.Item1;
}
}
#pragma warning restore CS0618
@ -176,7 +180,7 @@ namespace MessagePack.ReactivePropertyExtension
}
}
public class ReactiveCollectionFormatter<T> : SequneceFormatterBase<T, ReactiveCollection<T>>
public class ReactiveCollectionFormatter<T> : CollectionFormatterBase<T, ReactiveCollection<T>>
{
protected override void Add(ReactiveCollection<T> collection, int index, T value)
{

Просмотреть файл

@ -4,6 +4,11 @@
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.4\MessagePack.ReactiveProperty.xml</DocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ReactiveProperty" Version="3.5.0" />
<PackageReference Include="System.Reactive.PlatformServices" Version="3.1.1" />

Просмотреть файл

@ -37,9 +37,9 @@ namespace MessagePack.ReactivePropertyExtension
static readonly Dictionary<Type, Type> formatterMap = new Dictionary<Type, Type>()
{
{typeof(ReactiveProperty<>), typeof(ReactivePropertyFormatter<>)},
{typeof(ReactiveProperty<>), typeof(InterfaceReactivePropertyFormatter<>)},
{typeof(ReactiveProperty<>), typeof(InterfaceReadOnlyReactivePropertyFormatter<>)},
{typeof(ReactiveProperty<>), typeof(ReactiveCollectionFormatter<>)},
{typeof(IReactiveProperty<>), typeof(InterfaceReactivePropertyFormatter<>)},
{typeof(IReadOnlyReactiveProperty<>), typeof(InterfaceReadOnlyReactivePropertyFormatter<>)},
{typeof(ReactiveCollection<>), typeof(ReactiveCollectionFormatter<>)},
};
internal static object GetFormatter(Type t)
@ -55,10 +55,14 @@ namespace MessagePack.ReactivePropertyExtension
var ti = t.GetTypeInfo();
Type formatterType;
if (formatterMap.TryGetValue(t, out formatterType))
if (ti.IsGenericType)
{
return CreateInstance(formatterType, ti.GenericTypeArguments);
var genericType = ti.GetGenericTypeDefinition();
Type formatterType;
if (formatterMap.TryGetValue(genericType, out formatterType))
{
return CreateInstance(formatterType, ti.GenericTypeArguments);
}
}
return null;

Просмотреть файл

@ -5,6 +5,9 @@ using UnityEngine;
namespace MessagePack.Unity.Extension
{
/// <summary>
/// Special Resolver for Vector2[], Vector3[], Vector4[], Quaternion[], Color[], Bounds[], Rect[]
/// </summary>
public class UnityBlitResolver : IFormatterResolver
{
public static IFormatterResolver Instance = new UnityBlitResolver();
@ -29,7 +32,9 @@ namespace MessagePack.Unity.Extension
}
}
}
/// <summary>
/// Special Resolver for Vector2[], Vector3[], Vector4[], Quaternion[], Color[], Bounds[], Rect[] + int[], float[], double[]
/// </summary>
public class UnityBlitWithPrimitiveArrayResolver : IFormatterResolver
{
public static IFormatterResolver Instance = new UnityBlitWithPrimitiveArrayResolver();

Просмотреть файл

@ -95,7 +95,7 @@ namespace MessagePack.Unity.Extension
var result = new T[byteLength / StructLength];
CopyDeserializeUnsafe(ref bytes, offset, ref result, byteLength);
offset += readSize;
offset += byteLength;
readSize = offset - startOffset;
return result;

Просмотреть файл

@ -7,6 +7,8 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<DocumentationFile>bin\Release\netstandard1.4\MessagePack.UnityShims.xml</DocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

Просмотреть файл

@ -127,11 +127,11 @@ namespace MessagePack.Formatters
}
}
public abstract class SequneceFormatterBase<TElement, TIntermediate, TEnumerator, TSequence> : IMessagePackFormatter<TSequence>
where TSequence : IEnumerable<TElement>
public abstract class CollectionFormatterBase<TElement, TIntermediate, TEnumerator, TCollection> : IMessagePackFormatter<TCollection>
where TCollection : IEnumerable<TElement>
where TEnumerator : IEnumerator<TElement>
{
public int Serialize(ref byte[] bytes, int offset, TSequence value, IFormatterResolver formatterResolver)
public int Serialize(ref byte[] bytes, int offset, TCollection value, IFormatterResolver formatterResolver)
{
if (value == null)
{
@ -216,12 +216,12 @@ namespace MessagePack.Formatters
}
}
public TSequence Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
public TCollection Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
{
if (MessagePackBinary.IsNil(bytes, offset))
{
readSize = 1;
return default(TSequence);
return default(TCollection);
}
else
{
@ -244,7 +244,7 @@ namespace MessagePack.Formatters
}
// abstraction for serialize
protected virtual int? GetCount(TSequence sequence)
protected virtual int? GetCount(TCollection sequence)
{
var collection = sequence as ICollection<TElement>;
if (collection != null)
@ -263,33 +263,33 @@ namespace MessagePack.Formatters
}
// Some collections can use struct iterator, this is optimization path
protected abstract TEnumerator GetSourceEnumerator(TSequence source);
protected abstract TEnumerator GetSourceEnumerator(TCollection source);
// abstraction for deserialize
protected abstract TIntermediate Create(int count);
protected abstract void Add(TIntermediate collection, int index, TElement value);
protected abstract TSequence Complete(TIntermediate intermediateCollection);
protected abstract TCollection Complete(TIntermediate intermediateCollection);
}
public abstract class SequneceFormatterBase<TElement, TIntermediate, TSequence> : SequneceFormatterBase<TElement, TIntermediate, IEnumerator<TElement>, TSequence>
where TSequence : IEnumerable<TElement>
public abstract class CollectionFormatterBase<TElement, TIntermediate, TCollection> : CollectionFormatterBase<TElement, TIntermediate, IEnumerator<TElement>, TCollection>
where TCollection : IEnumerable<TElement>
{
protected override IEnumerator<TElement> GetSourceEnumerator(TSequence source)
protected override IEnumerator<TElement> GetSourceEnumerator(TCollection source)
{
return source.GetEnumerator();
}
}
public abstract class SequneceFormatterBase<TElement, TSequence> : SequneceFormatterBase<TElement, TSequence, TSequence>
where TSequence : IEnumerable<TElement>
public abstract class CollectionFormatterBase<TElement, TCollection> : CollectionFormatterBase<TElement, TCollection, TCollection>
where TCollection : IEnumerable<TElement>
{
protected sealed override TSequence Complete(TSequence intermediateCollection)
protected sealed override TCollection Complete(TCollection intermediateCollection)
{
return intermediateCollection;
}
}
public class GenericCollectionFormatter<TElement, TCollection> : SequneceFormatterBase<TElement, TCollection>
public class GenericCollectionFormatter<TElement, TCollection> : CollectionFormatterBase<TElement, TCollection>
where TCollection : ICollection<TElement>, new()
{
protected override TCollection Create(int count)
@ -303,7 +303,7 @@ namespace MessagePack.Formatters
}
}
public class ListFormatter<T> : SequneceFormatterBase<T, List<T>, List<T>.Enumerator, List<T>>
public class ListFormatter<T> : CollectionFormatterBase<T, List<T>, List<T>.Enumerator, List<T>>
{
protected override void Add(List<T> collection, int index, T value)
{
@ -326,7 +326,7 @@ namespace MessagePack.Formatters
}
}
public class LinkedListFormatter<T> : SequneceFormatterBase<T, LinkedList<T>, LinkedList<T>.Enumerator, LinkedList<T>>
public class LinkedListFormatter<T> : CollectionFormatterBase<T, LinkedList<T>, LinkedList<T>.Enumerator, LinkedList<T>>
{
protected override void Add(LinkedList<T> collection, int index, T value)
{
@ -349,7 +349,7 @@ namespace MessagePack.Formatters
}
}
public class QeueueFormatter<T> : SequneceFormatterBase<T, Queue<T>, Queue<T>.Enumerator, Queue<T>>
public class QeueueFormatter<T> : CollectionFormatterBase<T, Queue<T>, Queue<T>.Enumerator, Queue<T>>
{
protected override int? GetCount(Queue<T> sequence)
{
@ -377,21 +377,23 @@ namespace MessagePack.Formatters
}
}
public class StackFormatter<T> : SequneceFormatterBase<T, Stack<T>, Stack<T>.Enumerator, Stack<T>>
// should deserialize reverse order.
public class StackFormatter<T> : CollectionFormatterBase<T, T[], Stack<T>.Enumerator, Stack<T>>
{
protected override int? GetCount(Stack<T> sequence)
{
return sequence.Count;
}
protected override void Add(Stack<T> collection, int index, T value)
protected override void Add(T[] collection, int index, T value)
{
collection.Push(value);
// add reverse
collection[collection.Length - 1 - index] = value;
}
protected override Stack<T> Create(int count)
protected override T[] Create(int count)
{
return new Stack<T>(count);
return new T[count];
}
protected override Stack<T>.Enumerator GetSourceEnumerator(Stack<T> source)
@ -399,13 +401,13 @@ namespace MessagePack.Formatters
return source.GetEnumerator();
}
protected override Stack<T> Complete(Stack<T> intermediateCollection)
protected override Stack<T> Complete(T[] intermediateCollection)
{
return intermediateCollection;
return new Stack<T>(intermediateCollection);
}
}
public class HashSetFormatter<T> : SequneceFormatterBase<T, HashSet<T>, HashSet<T>.Enumerator, HashSet<T>>
public class HashSetFormatter<T> : CollectionFormatterBase<T, HashSet<T>, HashSet<T>.Enumerator, HashSet<T>>
{
protected override int? GetCount(HashSet<T> sequence)
{
@ -433,7 +435,7 @@ namespace MessagePack.Formatters
}
}
public class ReadOnlyCollectionFormatter<T> : SequneceFormatterBase<T, T[], ReadOnlyCollection<T>>
public class ReadOnlyCollectionFormatter<T> : CollectionFormatterBase<T, T[], ReadOnlyCollection<T>>
{
protected override void Add(T[] collection, int index, T value)
{
@ -451,7 +453,7 @@ namespace MessagePack.Formatters
}
}
public class ObservableCollectionFormatter<T> : SequneceFormatterBase<T, ObservableCollection<T>>
public class ObservableCollectionFormatter<T> : CollectionFormatterBase<T, ObservableCollection<T>>
{
protected override void Add(ObservableCollection<T> collection, int index, T value)
{
@ -464,7 +466,7 @@ namespace MessagePack.Formatters
}
}
public class ReadOnlyObservableCollectionFormatter<T> : SequneceFormatterBase<T, ObservableCollection<T>, ReadOnlyObservableCollection<T>>
public class ReadOnlyObservableCollectionFormatter<T> : CollectionFormatterBase<T, ObservableCollection<T>, ReadOnlyObservableCollection<T>>
{
protected override void Add(ObservableCollection<T> collection, int index, T value)
{
@ -482,7 +484,7 @@ namespace MessagePack.Formatters
}
}
public class InterfaceListFormatter<T> : SequneceFormatterBase<T, T[], IList<T>>
public class InterfaceListFormatter<T> : CollectionFormatterBase<T, T[], IList<T>>
{
protected override void Add(T[] collection, int index, T value)
{
@ -500,7 +502,7 @@ namespace MessagePack.Formatters
}
}
public class InterfaceCollectionFormatter<T> : SequneceFormatterBase<T, T[], ICollection<T>>
public class InterfaceCollectionFormatter<T> : CollectionFormatterBase<T, T[], ICollection<T>>
{
protected override void Add(T[] collection, int index, T value)
{
@ -518,7 +520,7 @@ namespace MessagePack.Formatters
}
}
public class InterfaceEnumerableFormatter<T> : SequneceFormatterBase<T, T[], IEnumerable<T>>
public class InterfaceEnumerableFormatter<T> : CollectionFormatterBase<T, T[], IEnumerable<T>>
{
protected override void Add(T[] collection, int index, T value)
{
@ -536,7 +538,7 @@ namespace MessagePack.Formatters
}
}
public class InterfaceReadOnlyListFormatter<T> : SequneceFormatterBase<T, T[], IReadOnlyList<T>>
public class InterfaceReadOnlyListFormatter<T> : CollectionFormatterBase<T, T[], IReadOnlyList<T>>
{
protected override void Add(T[] collection, int index, T value)
{
@ -554,7 +556,7 @@ namespace MessagePack.Formatters
}
}
public class InterfaceReadOnlyCollectionFormatter<T> : SequneceFormatterBase<T, T[], IReadOnlyCollection<T>>
public class InterfaceReadOnlyCollectionFormatter<T> : CollectionFormatterBase<T, T[], IReadOnlyCollection<T>>
{
protected override void Add(T[] collection, int index, T value)
{
@ -572,7 +574,7 @@ namespace MessagePack.Formatters
}
}
public class InterfaceSetFormatter<T> : SequneceFormatterBase<T, HashSet<T>, ISet<T>>
public class InterfaceSetFormatter<T> : CollectionFormatterBase<T, HashSet<T>, ISet<T>>
{
protected override void Add(HashSet<T> collection, int index, T value)
{
@ -590,7 +592,7 @@ namespace MessagePack.Formatters
}
}
public class ConcurrentBagFormatter<T> : SequneceFormatterBase<T, System.Collections.Concurrent.ConcurrentBag<T>>
public class ConcurrentBagFormatter<T> : CollectionFormatterBase<T, System.Collections.Concurrent.ConcurrentBag<T>>
{
protected override int? GetCount(ConcurrentBag<T> sequence)
{
@ -608,7 +610,7 @@ namespace MessagePack.Formatters
}
}
public class ConcurrentQueueFormatter<T> : SequneceFormatterBase<T, System.Collections.Concurrent.ConcurrentQueue<T>>
public class ConcurrentQueueFormatter<T> : CollectionFormatterBase<T, System.Collections.Concurrent.ConcurrentQueue<T>>
{
protected override int? GetCount(ConcurrentQueue<T> sequence)
{
@ -626,21 +628,27 @@ namespace MessagePack.Formatters
}
}
public class ConcurrentStackFormatter<T> : SequneceFormatterBase<T, System.Collections.Concurrent.ConcurrentStack<T>>
public class ConcurrentStackFormatter<T> : CollectionFormatterBase<T, T[], ConcurrentStack<T>>
{
protected override int? GetCount(ConcurrentStack<T> sequence)
{
return sequence.Count;
}
protected override void Add(ConcurrentStack<T> collection, int index, T value)
protected override void Add(T[] collection, int index, T value)
{
collection.Push(value);
// add reverse
collection[collection.Length - 1 - index] = value;
}
protected override ConcurrentStack<T> Create(int count)
protected override T[] Create(int count)
{
return new ConcurrentStack<T>();
return new T[count];
}
protected override ConcurrentStack<T> Complete(T[] intermediateCollection)
{
return new ConcurrentStack<T>(intermediateCollection);
}
}
@ -690,7 +698,7 @@ namespace MessagePack.Formatters
}
}
public class InterfaceLookupFormatter<TKey, TElement> : SequneceFormatterBase<IGrouping<TKey, TElement>, Dictionary<TKey, IGrouping<TKey, TElement>>, ILookup<TKey, TElement>>
public class InterfaceLookupFormatter<TKey, TElement> : CollectionFormatterBase<IGrouping<TKey, TElement>, Dictionary<TKey, IGrouping<TKey, TElement>>, ILookup<TKey, TElement>>
{
protected override void Add(Dictionary<TKey, IGrouping<TKey, TElement>> collection, int index, IGrouping<TKey, TElement> value)
{

Просмотреть файл

@ -263,7 +263,7 @@ namespace MessagePack.Formatters
{
l++;
}
if (k < kLength - 1)
else if (k < kLength - 1)
{
l = 0;
k++;

Просмотреть файл

@ -459,7 +459,7 @@ namespace MessagePack.Formatters
offset += MessagePackBinary.WriteBoolean(ref bytes, offset, value.Get(i));
}
return startOffset - offset;
return offset - startOffset;
}
}

Просмотреть файл

@ -278,7 +278,7 @@ namespace MessagePack.Internal
il.Emit(OpCodes.Throw);
}
/// <summary>for(var i = 0; i < ***; i++)</summary>
/// <summary>for var i = 0, i ..., i++ </summary>
public static void EmitIncrementFor(this ILGenerator il, LocalBuilder conditionGreater, Action<LocalBuilder> emitBody)
{
var loopBegin = il.DefineLabel();

Просмотреть файл

@ -11,6 +11,8 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<DocumentationFile>bin\Release\netstandard1.4\MessagePack.xml</DocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -257,7 +257,7 @@ namespace MessagePack
}
}
public static byte[] FastResizeClone(byte[] array, int newSize)
public static byte[] FastCloneWithResize(byte[] array, int newSize)
{
if (newSize < 0) throw new ArgumentOutOfRangeException("newSize");

Просмотреть файл

@ -15,6 +15,14 @@ namespace MessagePack
return ToJson(Serialize(obj));
}
/// <summary>
/// Dump to JSON string.
/// </summary>
public static string ToJson<T>(T obj, IFormatterResolver resolver)
{
return ToJson(Serialize(obj, resolver));
}
/// <summary>
/// Dump message-pack binary to JSON string.
/// </summary>

Просмотреть файл

@ -37,7 +37,7 @@ namespace MessagePack
var len = formatter.Serialize(ref buffer, 0, obj, resolver);
// do not return MemoryPool.Buffer.
return MessagePackBinary.FastResizeClone(buffer, len);
return MessagePackBinary.FastCloneWithResize(buffer, len);
}
/// <summary>

Просмотреть файл

@ -5,6 +5,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace MessagePack.Resolvers
{
@ -83,7 +84,7 @@ namespace MessagePack.Internal
{typeof(Guid?), new StaticNullableFormatter<Guid>(GuidFormatter.Instance)},
{typeof(Uri), UriFormatter.Instance},
{typeof(Version), VersionFormatter.Instance},
{typeof(StringBuilderFormatter), StringBuilderFormatter.Instance},
{typeof(StringBuilder), StringBuilderFormatter.Instance},
{typeof(BitArray), BitArrayFormatter.Instance},
// special primitive

Просмотреть файл

@ -69,7 +69,6 @@ namespace MessagePack.Internal
{typeof(IGrouping<,>), typeof(InterfaceGroupingFormatter<,>)},
{typeof(Lazy<>), typeof(LazyFormatter<>)},
{typeof(Task<>), typeof(TaskValueFormatter<>)},
{typeof(ValueTask<>), typeof(ValueTaskFormatter<>)},
};
// Reduce IL2CPP code generate size(don't write long code in <T>)
@ -122,6 +121,16 @@ namespace MessagePack.Internal
return CreateInstance(typeof(NullableFormatter<>), new[] { nullableElementType });
}
// ValueTask
else if (genericType == typeof(ValueTask<>))
{
return CreateInstance(typeof(ValueTaskFormatter<>), ti.GenericTypeArguments);
}
else if (isNullable && nullableElementType.IsConstructedGenericType && nullableElementType.GetGenericTypeDefinition() == typeof(ValueTask<>))
{
return CreateInstance(typeof(NullableFormatter<>), new[] { nullableElementType });
}
// Tuple
else if (ti.FullName.StartsWith("System.Tuple"))
{

Просмотреть файл

@ -0,0 +1,121 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace MessagePack.Tests
{
public class CollectionTest
{
T Convert<T>(T value)
{
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value));
}
public static object collectionTestData = new object[]
{
new object[]{ new int[]{ 1,10, 100 } , null },
new object[]{ new List<int>{ 1,10, 100 } , null },
new object[]{ new LinkedList<int>(new[] { 1, 10, 100 }) , null },
new object[]{ new Queue<int>(new[] { 1, 10, 100 }) , null },
new object[]{ new HashSet<int>(new[] { 1, 10, 100 }), null },
new object[]{ new ReadOnlyCollection<int>(new[] { 1, 10, 100 }), null },
new object[]{ new ObservableCollection<int>(new[] { 1, 10, 100 }), null },
new object[]{ new ReadOnlyObservableCollection<int>(new ObservableCollection<int>(new[] { 1, 10, 100 })), null },
};
[Theory]
[MemberData(nameof(collectionTestData))]
public void ConcreteCollectionTest<T>(T x, T y)
{
Convert(x).IsStructuralEqual(x);
Convert(y).IsStructuralEqual(y);
}
[Fact]
public void InterfaceCollectionTest()
{
var a = (IList<int>)new int[] { 1, 10, 100 };
var b = (ICollection<int>)new int[] { 1, 10, 100 };
var c = (Enumerable.Range(1, 100).AsEnumerable());
var d = (IReadOnlyList<int>)new int[] { 1, 10, 100 };
var e = (IReadOnlyCollection<int>)new int[] { 1, 10, 100 };
var f = (ISet<int>)new HashSet<int>(new[] { 1, 10, 100 });
var g = (ILookup<bool, int>)Enumerable.Range(1, 100).ToLookup(x => x % 2 == 0);
Convert(a).Is(a);
Convert(b).Is(b);
Convert(c).Is(c);
Convert(d).Is(d);
Convert(e).Is(e);
Convert(f).Is(f);
Convert(g).Is(g);
a = null;
b = null;
c = null;
d = null;
e = null;
f = null;
g = null;
Convert(a).Is(a);
Convert(b).Is(b);
Convert(c).IsNull();
Convert(d).Is(d);
Convert(e).Is(e);
Convert(f).Is(f);
Convert(g).Is(g);
}
[Fact]
public void StackTest()
{
var stack = new Stack<int>(new[] { 1, 10, 100 });
stack.AsEnumerable().Is(100, 10, 1);
Convert(stack).AsEnumerable().Is(100, 10, 1);
stack = new Stack<int>();
Convert(stack).AsEnumerable().Count().Is(0);
stack = null;
Convert(stack).IsNull();
}
[Fact]
public void ConcurrentCollectionTest()
{
var c0 = new ConcurrentQueue<int>(new[] { 1, 10, 100 });
var c1 = new ConcurrentStack<int>(new[] { 1, 10, 100 });
var c2 = new ConcurrentBag<int>(new[] { 1, 10, 100 });
Convert(c0).Is(1, 10, 100);
Convert(c1).Is(100, 10, 1);
Convert(c2).OrderBy(x => x).Is(1, 10, 100);
c0 = null;
c1 = null;
c2 = null;
Convert(c0).IsNull();
Convert(c1).IsNull();
Convert(c2).IsNull();
}
[Fact]
public void ArraySegmentTest()
{
var test = new ArraySegment<int>(new[] { 1, 10, 100 });
Convert(test).Is(1, 10, 100);
ArraySegment<int>? nullableTest = new ArraySegment<int>(new[] { 1, 10, 100 });
Convert(nullableTest).Is(1, 10, 100);
nullableTest = null;
Convert(nullableTest).IsNull();
}
}
}

Просмотреть файл

@ -0,0 +1,67 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace MessagePack.Tests
{
public class DictionaryTest
{
T Convert<T>(T value)
{
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value));
}
public static object dictionaryTestData = new object[]
{
new object[]{ new Dictionary<int, int>() { { 1, 100 } }, null },
new object[]{ new ReadOnlyDictionary<int,int>(new Dictionary<int, int>() { { 1, 100 } }), null },
new object[]{ new SortedList<int, int>() { { 1, 100 } }, null },
new object[]{ new SortedDictionary<int, int>() { { 1, 100 } }, null },
};
[Theory]
[MemberData(nameof(dictionaryTestData))]
public void DictionaryTestAll<T>(T x, T y)
{
Convert(x).IsStructuralEqual(x);
Convert(y).IsStructuralEqual(y);
}
[Fact]
public void InterfaceDictionaryTest()
{
var a = (IDictionary<int, int>)new Dictionary<int, int>() { { 1, 100 } };
var b = (IReadOnlyDictionary<int, int>)new Dictionary<int, int>() { { 1, 100 } };
var c = (IDictionary<int, int>)null;
var d = (IReadOnlyDictionary<int, int>)null;
Convert(a).IsStructuralEqual(a);
Convert(b).IsStructuralEqual(b);
Convert(c).IsStructuralEqual(c);
Convert(d).IsStructuralEqual(d);
}
[Fact]
public void ConcurrentDictionaryTest()
{
var cd = new ConcurrentDictionary<int, int>();
cd.TryAdd(1, 100);
cd.TryAdd(2, 200);
cd.TryAdd(3, 300);
var conv = Convert(cd);
conv[1].Is(100);
conv[2].Is(200);
conv[3].Is(300);
cd = null;
Convert(cd).IsNull();
}
}
}

Просмотреть файл

@ -0,0 +1,91 @@
using MessagePack.ImmutableCollections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MessagePack.Formatters;
using MessagePack.Resolvers;
using System.Collections.Immutable;
using Xunit;
namespace MessagePack.Tests.ExtensionTests
{
public class WithImmutableDefaultResolver : IFormatterResolver
{
public IMessagePackFormatter<T> GetFormatter<T>()
{
return (ImmutableCollectionResolver.Instance.GetFormatter<T>()
?? DefaultResolver.Instance.GetFormatter<T>());
}
}
public class ImmutableCollectionTest
{
T Convert<T>(T value)
{
var resolver = new WithImmutableDefaultResolver();
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value, resolver), resolver);
}
public static object collectionTestData = new object[]
{
new object[]{ ImmutableList<int>.Empty.AddRange(new[] { 1, 10, 100 }) , null },
new object[]{ ImmutableDictionary<int,int>.Empty.AddRange(new Dictionary<int,int> { { 1, 10 },{ 2, 10 }, { 3, 100 } }) , null },
new object[]{ ImmutableHashSet<int>.Empty.Add(1).Add(10).Add(100) , null },
new object[]{ ImmutableSortedDictionary<int,int>.Empty.AddRange(new Dictionary<int,int> { { 1, 10 },{ 2, 10 }, { 3, 100 } }) , null },
new object[]{ ImmutableSortedSet<int>.Empty.Add(1).Add(10).Add(100) , null },
new object[]{ ImmutableQueue<int>.Empty.Enqueue(1).Enqueue(10).Enqueue(100) , null },
new object[]{ ImmutableStack<int>.Empty.Push(1).Push(10).Push(100) , null },
};
[Theory]
[MemberData(nameof(collectionTestData))]
public void ConcreteCollectionTest<T>(T x, T y)
{
Convert(x).IsStructuralEqual(x);
Convert(y).IsStructuralEqual(y);
}
[Fact]
public void InterfaceCollectionTest()
{
IImmutableList<int> a = ImmutableList<int>.Empty.AddRange(new[] { 1, 10, 100 });
IImmutableDictionary<int, int> b = ImmutableDictionary<int, int>.Empty.AddRange(new Dictionary<int, int> { { 1, 10 }, { 2, 10 }, { 3, 100 } });
IImmutableSet<int> c = ImmutableHashSet<int>.Empty.Add(1).Add(10).Add(100);
IImmutableQueue<int> d = ImmutableQueue<int>.Empty.Enqueue(1).Enqueue(10).Enqueue(100);
IImmutableStack<int> e = ImmutableStack<int>.Empty.Push(1).Push(10).Push(100);
Convert(a).IsStructuralEqual(a);
Convert(b).IsStructuralEqual(b);
Convert(c).IsStructuralEqual(c);
Convert(d).IsStructuralEqual(d);
Convert(e).IsStructuralEqual(e);
a = null;
b = null;
c = null;
d = null;
e = null;
Convert(a).IsNull();
Convert(b).IsNull();
Convert(c).IsNull();
Convert(d).IsNull();
Convert(e).IsNull();
}
[Fact]
public void ImmutableArrayTest()
{
var a = ImmutableArray.CreateRange(new[] { 1, 10, 100 });
ImmutableArray<int>? b = ImmutableArray.CreateRange(new[] { 1, 10, 100 });
ImmutableArray<int>? c = null;
Convert(a).Is(1, 10, 100);
Convert(b).Is(1, 10, 100);
Convert(c).IsNull();
}
}
}

Просмотреть файл

@ -0,0 +1,103 @@
using MessagePack.Formatters;
using System.Reactive.Linq;
using MessagePack.ReactivePropertyExtension;
using MessagePack.Resolvers;
using Reactive.Bindings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using System.Reactive;
namespace MessagePack.Tests.ExtensionTests
{
public class WithRxPropDefaultResolver : IFormatterResolver
{
public IMessagePackFormatter<T> GetFormatter<T>()
{
return (ReactivePropertyResolver.Instance.GetFormatter<T>()
?? DefaultResolver.Instance.GetFormatter<T>());
}
}
public class ReactivePropertyTest
{
T Convert<T>(T value)
{
var resolver = new WithRxPropDefaultResolver();
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value, resolver), resolver);
}
[Fact]
public void ViewModelTest()
{
var vm = new ViewModel(10, 20, 30);
var deserialized = Convert(vm);
deserialized.Prop1.Value.Is(10);
deserialized.Prop2.Value.Is(20);
deserialized.Prop3.Value.Is(30);
deserialized.Prop4.Value.Is(60);
// dump serialized
var data = MessagePackSerializer.ToJson(vm, new WithRxPropDefaultResolver());
// 3 = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe
// -1 = UIDispatcherScheduler.Default
// Prop1:[3, -1, 10]
// Prop2:[3, -1, 10]
// Prop3:[3, -1, 10]
data.Is("[[3,-1,10],[3,-1,20],[3,-1,30]]");
}
[Fact]
public void MiscTest()
{
var rxCol = new ReactiveCollection<int> { 1, 10, 100 };
Convert(rxCol).Is(1, 10, 100);
Convert(Unit.Default).Is(Unit.Default);
Unit? nullUnit = null;
Convert(nullUnit).Is(Unit.Default);
}
}
[MessagePackObject]
public class ViewModel : IMessagePackSerializationCallbackReceiver
{
[Key(0)]
public ReactiveProperty<int> Prop1 { get; private set; }
[Key(1)]
public IReactiveProperty<int> Prop2 { get; private set; }
[Key(2)]
public IReadOnlyReactiveProperty<int> Prop3 { get; private set; }
[Ignore]
public IReadOnlyReactiveProperty<int> Prop4 { get; private set; }
public ViewModel(int x, int y, int z)
: this(new ReactiveProperty<int>(x), new ReactiveProperty<int>(y), new ReactiveProperty<int>(z))
{
}
[SerializationConstructor]
public ViewModel(ReactiveProperty<int> x, IReactiveProperty<int> y, IReadOnlyReactiveProperty<int> z)
{
Prop1 = x;
Prop2 = y;
Prop3 = z;
OnAfterDeserialize();
}
public void OnAfterDeserialize()
{
Prop4 = Prop1.CombineLatest(Prop2, (x, y) => (x + y) * 2).ToReadOnlyReactiveProperty();
}
public void OnBeforeSerialize()
{
}
}
}

Просмотреть файл

@ -0,0 +1,80 @@
using MessagePack.Formatters;
using MessagePack.Resolvers;
using MessagePack.Unity.Extension;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Xunit;
namespace MessagePack.Tests.ExtensionTests
{
public class WithUnityBlitResolver : IFormatterResolver
{
public IMessagePackFormatter<T> GetFormatter<T>()
{
return (UnityBlitWithPrimitiveArrayResolver.Instance.GetFormatter<T>()
?? DefaultResolver.Instance.GetFormatter<T>());
}
}
public class UnityShimTest
{
public static object[] testData = new object[]
{
new object[]{ BlitContainer<Vector2>.Create(Enumerable.Range(1, 123).Select(x => new Vector2(x, x)))},
new object[]{ BlitContainer<Vector3>.Create(Enumerable.Range(1, 123).Select(x => new Vector3(x,x, x)))},
new object[]{ BlitContainer<Vector4>.Create(Enumerable.Range(1, 123).Select(x => new Vector4(x,x,x, x)))},
new object[]{ BlitContainer<Quaternion>.Create(Enumerable.Range(1, 123).Select(x => new Quaternion(x,x,x, x)))},
new object[]{ BlitContainer<Color>.Create(Enumerable.Range(1, 123).Select(x => new Color(x,x,x, x)))},
new object[]{ BlitContainer<Bounds>.Create(Enumerable.Range(1, 123).Select(x => new Bounds(new Vector3(x,x,x), new Vector3(x,x,x))))},
new object[]{ BlitContainer<Rect>.Create(Enumerable.Range(1, 123).Select(x => new Rect(x,x,x, x)))},
new object[]{ BlitContainer<int>.Create(Enumerable.Range(1, 123).Select(x => x))},
new object[]{ BlitContainer<float>.Create(Enumerable.Range(1, 123).Select(x => (float)x))},
new object[]{ BlitContainer<double>.Create(Enumerable.Range(1, 123).Select(x => (double)x))},
};
T Convert<T>(T value)
{
var resolver = new WithUnityBlitResolver();
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value, resolver), resolver);
}
[Theory]
[MemberData(nameof(testData))]
public void BlitTest<T>(BlitContainer<T> blit)
{
var huga = Convert(blit.Array);
huga.IsStructuralEqual(blit.Array);
Convert(blit).IsStructuralEqual(blit);
blit.Array = null;
Convert(blit).Array.IsNull();
}
}
[MessagePackObject]
public class BlitContainer<T>
{
[Key(0)]
public string Dummy1 { get; set; }
[Key(1)]
public T[] Array { get; set; }
[Key(2)]
public string Dummy2 { get; set; }
public static BlitContainer<T> Create(IEnumerable<T> array)
{
return new BlitContainer<T>()
{
Array = array.ToArray(),
Dummy1 = Guid.NewGuid().ToString(),
Dummy2 = Guid.NewGuid().ToString()
};
}
}
}

Просмотреть файл

@ -1,5 +1,6 @@
using SharedData;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -113,9 +114,11 @@ namespace MessagePack.Tests
public static object[] standardClassFormatterTestData = new object[]
{
new object[] { new byte[] { 1, 10, 100 }, new byte[0] { }, null },
new object[] { "aaa", "", null },
new object[] { new Uri("Http://hogehoge.com"), new Uri("Https://hugahuga.com"), null },
new object[] { new Version(1,2), new Version(100,200,300,400), null },
new object[] { new BitArray(new[] { true, false, true }), new BitArray(1), null },
};
[Theory]
@ -126,5 +129,50 @@ namespace MessagePack.Tests
Convert(y).Is(y);
Convert(z).Is(z);
}
[Fact]
public void StringBuilderTest()
{
var sb = new StringBuilder("aaa");
Convert(sb).ToString().Is("aaa");
StringBuilder nullSb = null;
Convert(nullSb).IsNull();
}
[Fact]
public void LazyTest()
{
var lz = new Lazy<int>(() => 100);
Convert(lz).Value.Is(100);
Lazy<int> nullLz = null;
Convert(nullLz).IsNull();
}
[Fact]
public void TaskTest()
{
var intTask = Task.Run(() => 100);
Convert(intTask).Result.Is(100);
Task<int> nullTask = null;
Convert(nullTask).IsNull();
Task unitTask = Task.Run(() => 100);
Convert(unitTask).Status.Is(TaskStatus.RanToCompletion);
Task nullUnitTask = null;
Convert(nullUnitTask).Status.Is(TaskStatus.RanToCompletion); // write to nil
ValueTask<int> valueTask = new ValueTask<int>(100);
Convert(valueTask).Result.Is(100);
ValueTask<int>? nullValueTask = new ValueTask<int>(100);
Convert(nullValueTask).Value.Result.Is(100);
ValueTask<int>? nullValueTask2 = null;
Convert(nullValueTask2).IsNull();
}
}
}

Просмотреть файл

@ -33,6 +33,27 @@ namespace MessagePack.Tests
Convert(data).IsStructuralEqual(data);
}
public static object[] valueTupleTestData = new object[]
{
new object[] { ValueTuple.Create(1),null },
new object[] { ValueTuple.Create(1,2),null },
new object[] { ValueTuple.Create(1,2,3),null },
new object[] { ValueTuple.Create(1,2,3,4),null },
new object[] { ValueTuple.Create(1,2,3,4,5) ,null},
new object[] { ValueTuple.Create(1,2,3,4,5,6) ,null},
new object[] { ValueTuple.Create(1,2,3,4,5,6,7) ,null},
new object[] { ValueTuple.Create(1,2,3,4,5,6,7,8) ,null},
};
[Theory]
[MemberData(nameof(tupleTestData))]
public void TupleTest<T>(T data, T? @null)
where T : struct
{
Convert(data).IsStructuralEqual(data);
Convert(@null).IsNull();
}
public static object[] keyValuePairData = new object[]
{
new object[] { new KeyValuePair<int, int>(1,2), null },

Просмотреть файл

@ -28,6 +28,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@ -36,18 +37,54 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="MsgPack, Version=0.9.0.0, Culture=neutral, PublicKeyToken=a2625990d5dc0167, processorArchitecture=MSIL">
<HintPath>..\..\packages\MsgPack.Cli.0.9.0-beta2\lib\net46\MsgPack.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="ReactiveProperty, Version=3.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ReactiveProperty.3.5.0\lib\net46\ReactiveProperty.dll</HintPath>
</Reference>
<Reference Include="ReactiveProperty.NET46, Version=3.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ReactiveProperty.3.5.0\lib\net46\ReactiveProperty.NET46.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Reactive.Core, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.Core.3.1.1\lib\net46\System.Reactive.Core.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Interfaces, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.Interfaces.3.1.1\lib\net45\System.Reactive.Interfaces.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Linq, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.Linq.3.1.1\lib\net46\System.Reactive.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.PlatformServices, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.PlatformServices.3.1.1\lib\net46\System.Reactive.PlatformServices.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Windows.Threading, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
@ -62,10 +99,16 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CollectionTest.cs" />
<Compile Include="DictionaryTest.cs" />
<Compile Include="ExtensionTests\ImmutableCollectionTest.cs" />
<Compile Include="ExtensionTests\ReactivePropertyTest.cs" />
<Compile Include="ExtensionTests\UnityShimTest.cs" />
<Compile Include="FormatterTest.cs" />
<Compile Include="GenericFormatters.cs" />
<Compile Include="MessagePackBinaryTest.cs" />
<Compile Include="MessagePackSerializerTest.cs" />
<Compile Include="MultiDimentionalArrayTest.cs" />
<Compile Include="ObjectResolverTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnionResolverTest.cs" />
@ -73,6 +116,7 @@
<Compile Include="Utils\ChainingAssertion.Xunit.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
@ -80,11 +124,24 @@
<Project>{3abc5c4c-2ce4-459e-8666-f2b181c3def3}</Project>
<Name>SharedData</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\MessagePack.ImmutableCollections\MessagePack.ImmutableCollections.csproj">
<Project>{1e778228-8f36-41fb-8b66-a4a5a753ebde}</Project>
<Name>MessagePack.ImmutableCollections</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\MessagePack.ReactiveProperty\MessagePack.ReactiveProperty.csproj">
<Project>{166a16c0-b89f-41af-956a-235c6ca62c25}</Project>
<Name>MessagePack.ReactiveProperty</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\MessagePack.UnityShims\MessagePack.UnityShims.csproj">
<Project>{c01e1407-7fec-4c1d-b0b4-74d95a317aa6}</Project>
<Name>MessagePack.UnityShims</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\MessagePack\MessagePack.csproj">
<Project>{7abb33ee-a2f1-492b-8daf-5df89f0f0b79}</Project>
<Name>MessagePack</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

Просмотреть файл

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace MessagePack.Tests
{
public class MultiDimentionalArrayTest
{
T Convert<T>(T value)
{
return MessagePackSerializer.Deserialize<T>(MessagePackSerializer.Serialize(value));
}
[Theory]
[InlineData(100, 100, 10, 5)]
[InlineData(10, 20, 15, 5)]
[InlineData(3, 5, 10, 15)]
[InlineData(3, 5, 10, 15)]
public void MultiDimentional(int dataI, int dataJ, int dataK, int dataL)
{
var two = new ValueTuple<int, int>[dataI, dataJ];
var three = new ValueTuple<int, int, int>[dataI, dataJ, dataK];
var four = new ValueTuple<int, int, int, int>[dataI, dataJ, dataK, dataL];
for (int i = 0; i < dataI; i++)
{
for (int j = 0; j < dataJ; j++)
{
two[i, j] = (i, j);
for (int k = 0; k < dataK; k++)
{
three[i, j, k] = (i, j, k);
for (int l = 0; l < dataL; l++)
{
four[i, j, k, l] = (i, j, k, l);
}
}
}
}
var cTwo = Convert(two);
var cThree = Convert(three);
var cFour = Convert(four);
cTwo.Length.Is(two.Length);
cThree.Length.Is(three.Length);
cFour.Length.Is(four.Length);
for (int i = 0; i < dataI; i++)
{
for (int j = 0; j < dataJ; j++)
{
cTwo[i, j].Is(two[i, j]);
for (int k = 0; k < dataK; k++)
{
cThree[i, j, k].Is(three[i, j, k]);
for (int l = 0; l < dataL; l++)
{
cFour[i, j, k, l].Is(four[i, j, k, l]);
}
}
}
}
}
}
}

Просмотреть файл

@ -209,7 +209,7 @@ namespace MessagePack.Tests
}
{
var before = false;
var c1 = new Callback2(0, () => before = true, () => { });
var d = MessagePackSerializer.Serialize(c1);
before.IsTrue();
@ -225,7 +225,7 @@ namespace MessagePack.Tests
}
{
var before = false;
var c1 = new Callback2_2(0, () => before = true, () => { });
var d = MessagePackSerializer.Serialize(c1);
before.IsTrue();
@ -235,5 +235,23 @@ namespace MessagePack.Tests
Callback2_2.CalledAfter.IsTrue();
}
}
[Fact]
public void GenericClassTest()
{
var t = new GenericClass<int, string> { MyProperty0 = 100, MyProperty1 = "aaa" };
var v = Convert(t);
v.MyProperty0.Is(100);
v.MyProperty1.Is("aaa");
}
[Fact]
public void GenericStructTest()
{
var t = new GenericStruct<int, string> { MyProperty0 = 100, MyProperty1 = "aaa" };
var v = Convert(t);
v.MyProperty0.Is(100);
v.MyProperty1.Is("aaa");
}
}
}

Просмотреть файл

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Interfaces" publicKeyToken="94bc3704cddfc263" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1000.0" newVersion="3.0.1000.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reactive.Linq" publicKeyToken="94bc3704cddfc263" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Просмотреть файл

@ -1,6 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MsgPack.Cli" version="0.9.0-beta2" targetFramework="net462" />
<package id="ReactiveProperty" version="3.5.0" targetFramework="net461" />
<package id="System.Collections.Immutable" version="1.3.1" targetFramework="net461" />
<package id="System.Reactive" version="3.1.1" targetFramework="net461" />
<package id="System.Reactive.Core" version="3.1.1" targetFramework="net461" />
<package id="System.Reactive.Interfaces" version="3.1.1" targetFramework="net461" />
<package id="System.Reactive.Linq" version="3.1.1" targetFramework="net461" />
<package id="System.Reactive.PlatformServices" version="3.1.1" targetFramework="net461" />
<package id="System.Reactive.Windows.Threading" version="3.1.1" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.3.0" targetFramework="net462" />
<package id="xunit" version="2.2.0-rc1-build3507" targetFramework="net462" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net462" />