Skip to content

Commit 138d911

Browse files
committed
Add netstandard2.0 drop and its unit tests.
.NET Standard 2.0 drop supports serializer code generation with CodeDOM. Note that assembly generation with Reflection.Emit is not supported, so net45/46 drops are still usable. And there are Xamarin and UWP drops to supoort their AOT environment.
1 parent 3a992cc commit 138d911

File tree

50 files changed

+463
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+463
-163
lines changed

MsgPack.Common.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netcoreapp1.0'">
6565
<DefineConstants>$(DefineConstants);FEATURE_TAP;FEATURE_CONCURRENT;FEATURE_MEMCOPY</DefineConstants>
6666
</PropertyGroup>
67+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netcoreapp2.0'">
68+
<DefineConstants>$(DefineConstants);FEATURE_TAP;FEATURE_CONCURRENT;FEATURE_POINTER_CONVERSION;FEATURE_MEMCOPY</DefineConstants>
69+
</PropertyGroup>
6770
<PropertyGroup Condition="'$(TargetFramework)' == 'MonoAndroid10' or '$(TargetFramework)' == 'Xamarin.iOS10'">
6871
<DefineConstants>$(DefineConstants);__MOBILE__;AOT;XAMARIN;FEATURE_TAP;FEATURE_CONCURRENT;FEATURE_POINTER_CONVERSION;FEATURE_MEMCOPY</DefineConstants>
6972
</PropertyGroup>

src/MsgPack/MsgPack.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ProjectGuid>{5BCEC32E-990E-4DE5-945F-BD27326A7418}</ProjectGuid>
55
<OutputType>Library</OutputType>
66
<AssemblyName>MsgPack</AssemblyName>
7-
<TargetFrameworks>net46;net35;net45;netstandard1.1;netstandard1.3;MonoAndroid10;Xamarin.iOS10</TargetFrameworks>
7+
<TargetFrameworks>net46;net35;net45;netstandard1.1;netstandard1.3;netstandard2.0;MonoAndroid10;Xamarin.iOS10</TargetFrameworks>
88
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
99
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
1010
<NuspecFile>$(SolutionDir)/msgpack.nuspec</NuspecFile>
@@ -76,6 +76,13 @@
7676
<PackageReference Include="System.Reflection.Emit" Version="4.0.1" />
7777
<PackageReference Include="System.Reflection.Emit.LightWeight" Version="4.0.1" />
7878
</ItemGroup>
79+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
80+
<PackageReference Include="NETStandard.Library" Version="2.0.0" />
81+
<PackageReference Include="System.CodeDom" Version="4.4.0" />
82+
<PackageReference Include="System.Numerics.Vectors" Version="4.3.0" />
83+
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
84+
<PackageReference Include="System.Reflection.Emit.LightWeight" Version="4.3.0" />
85+
</ItemGroup>
7986
<ItemGroup>
8087
<Compile Include="..\CommonAssemblyInfo.cs">
8188
<Link>Properties\CommonAssemblyInfo.cs</Link>
@@ -502,7 +509,7 @@
502509
<Compile Remove="Serialization\DefaultSerializers\UnixEpocFileTimeMessagePackSerializer.cs" />
503510
<Compile Remove="Serialization\ReflectionExtensions.ConstructorDelegate.cs" />
504511
</ItemGroup>
505-
<ItemGroup Condition="'$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net46' or '$(TargetFramework)' == 'netstandard1.1' or '$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'uap10.0' or '$(TargetFramework)' == 'MonoAndroid10' or '$(TargetFramework)' == 'Xamarin.iOS10'">
512+
<ItemGroup Condition="'$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net46' or '$(TargetFramework)' == 'netstandard1.1' or '$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'uap10.0' or '$(TargetFramework)' == 'MonoAndroid10' or '$(TargetFramework)' == 'Xamarin.iOS10'">
506513
<Compile Include="AsyncReadResult.cs" />
507514
<Compile Include="AsyncReadResult`1.cs" />
508515
<Compile Include="TaskAugument.cs" />

src/MsgPack/Serialization/EmittingSerializers/AssemblyBuilderCodeGenerationContext.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2010-2016 FUJIWARA, Yusuke
5+
// Copyright (C) 2010-2017 FUJIWARA, Yusuke
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -101,6 +101,9 @@ out serializerTypeNamespace
101101
/// <returns>A <see cref="SerializerCodeGenerationResult"/> collection which correspond to genereated codes.</returns>
102102
public IEnumerable<SerializerCodeGenerationResult> Generate()
103103
{
104+
#if NETSTANDARD2_0
105+
throw new PlatformNotSupportedException( "Assembly generation is not supported in .NET Standard." );
106+
#else
104107
var assemblyFileName = this._assemblyBuilder.GetName().Name + ".dll";
105108
this._assemblyBuilder.Save( assemblyFileName );
106109
var assemblyFilePath =
@@ -121,6 +124,7 @@ public IEnumerable<SerializerCodeGenerationResult> Generate()
121124
s.SerializerTypeName
122125
)
123126
);
127+
#endif // NETSTANDARD2_0
124128
}
125129
}
126-
}
130+
}

src/MsgPack/Serialization/EmittingSerializers/SerializationMethodGeneratorManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2010-2016 FUJIWARA, Yusuke
5+
// Copyright (C) 2010-2017 FUJIWARA, Yusuke
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -169,7 +169,7 @@ private SerializationMethodGeneratorManager( bool isDebuggable, bool isCollectab
169169
{
170170
assemblyName = typeof( SerializationMethodGeneratorManager ).Namespace + ".GeneratedSerealizers" + Interlocked.Increment( ref _assemblySequence );
171171
var dedicatedAssemblyBuilder =
172-
#if !NETSTANDARD1_1 && !NETSTANDARD1_3
172+
#if !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
173173
AppDomain.CurrentDomain.DefineDynamicAssembly(
174174
new AssemblyName( assemblyName ),
175175
isDebuggable
@@ -189,13 +189,13 @@ private SerializationMethodGeneratorManager( bool isDebuggable, bool isCollectab
189189
new AssemblyName( assemblyName ),
190190
isCollectable ? AssemblyBuilderAccess.RunAndCollect : AssemblyBuilderAccess.Run
191191
);
192-
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
192+
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
193193

194194
SetUpAssemblyBuilderAttributes( dedicatedAssemblyBuilder, isDebuggable );
195195
this._assembly = dedicatedAssemblyBuilder;
196196
}
197197

198-
#if !NETSTANDARD1_1 && !NETSTANDARD1_3
198+
#if !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
199199
if ( isDebuggable )
200200
{
201201
this._module = this._assembly.DefineDynamicModule( assemblyName, assemblyName + ".dll", true );
@@ -206,7 +206,7 @@ private SerializationMethodGeneratorManager( bool isDebuggable, bool isCollectab
206206
}
207207
#else
208208
this._module = this._assembly.DefineDynamicModule( assemblyName );
209-
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
209+
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
210210
}
211211

212212
internal static void SetUpAssemblyBuilderAttributes( AssemblyBuilder dedicatedAssemblyBuilder, bool isDebuggable )

src/MsgPack/Serialization/EmittingSerializers/SerializerEmitter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2010-2016 FUJIWARA, Yusuke
5+
// Copyright (C) 2010-2017 FUJIWARA, Yusuke
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -78,12 +78,12 @@ public SerializerEmitter( ModuleBuilder host, SerializerSpecification specificat
7878
#endif // DEBUG
7979
this._isDebuggable = isDebuggable;
8080

81-
#if DEBUG && !NET35 && !NETSTANDARD1_1 && !NETSTANDARD1_3
81+
#if DEBUG && !NET35 && !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
8282
if ( isDebuggable && SerializerDebugging.DumpEnabled )
8383
{
8484
SerializerDebugging.PrepareDump( host.Assembly as AssemblyBuilder );
8585
}
86-
#endif // DEBUG && !NET35 && !NETSTANDARD1_1 && !NETSTANDARD1_3
86+
#endif // DEBUG && !NET35 && !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
8787
}
8888

8989
#region -- Field --
@@ -284,4 +284,4 @@ private ConstructorBuilder CreateConstructor( MethodAttributes attributes, Type[
284284

285285
#endregion -- Constructor --
286286
}
287-
}
287+
}

src/MsgPack/Serialization/EmittingSerializers/SerializerEmitter.enum.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2014-2016 FUJIWARA, Yusuke
5+
// Copyright (C) 2014-2017 FUJIWARA, Yusuke
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -88,11 +88,11 @@ public Func<SerializationContext, EnumSerializationMethod, MessagePackSerializer
8888
);
8989
var ctor =
9090
this._typeBuilder
91-
#if !NETSTANDARD1_1 && !NETSTANDARD1_3
91+
#if !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
9292
.CreateType()
9393
#else
9494
.CreateTypeInfo().AsType()
95-
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
95+
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
9696
.GetRuntimeConstructor( ContextAndEnumSerializationMethodConstructorParameterTypes );
9797
#if DEBUG
9898
Contract.Assert( ctor != null, "ctor != null" );
@@ -138,4 +138,4 @@ private void EmitMethodEnumConstructor( Type baseType, TracingILGenerator il )
138138
il.EmitRet();
139139
}
140140
}
141-
}
141+
}

src/MsgPack/Serialization/EmittingSerializers/SerializerEmitter.object.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2010-2016 FUJIWARA, Yusuke
5+
// Copyright (C) 2010-2017 FUJIWARA, Yusuke
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -270,11 +270,11 @@ public void DefineUnpackingContext( string name, IList<KeyValuePair<string, Type
270270
#endif // DEBUG
271271
}
272272

273-
#if !NETSTANDARD1_1 && !NETSTANDARD1_3
273+
#if !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
274274
type = this._unpackingContextType.CreateType();
275275
#else
276276
type = this._unpackingContextType.CreateTypeInfo().AsType();
277-
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
277+
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
278278
constructor = type.GetConstructors().Single();
279279
}
280280

@@ -407,11 +407,11 @@ public Func<SerializationContext, PolymorphismSchema, MessagePackSerializer> Cre
407407
( _, il ) => CreateDefaultObjectConstructor( contextfulConstructor, il )
408408
);
409409

410-
#if !NETSTANDARD1_1 && !NETSTANDARD1_3
410+
#if !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
411411
var ctor = this._typeBuilder.CreateType().GetConstructor( ConstructorParameterTypesWithoutCapabilities );
412412
#else
413413
var ctor = this._typeBuilder.CreateTypeInfo().GetConstructor( ConstructorParameterTypesWithoutCapabilities );
414-
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
414+
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
415415

416416
#if DEBUG
417417
Contract.Assert( ctor != null, "ctor != null" );

src/MsgPack/Serialization/Reflection/TracingILGenerator.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#region -- License Terms --
1+
#region -- License Terms --
22
//
33
// NLiblet
44
//
5-
// Copyright (C) 2011-2016 FUJIWARA, Yusuke and contributors
5+
// Copyright (C) 2011-2017 FUJIWARA, Yusuke and contributors
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -352,7 +352,7 @@ private LocalBuilder DeclareLocalCore( Type localType, string name )
352352
var result = this._underlying.DeclareLocal( localType );
353353
this._localDeclarations.Add( result, name );
354354
// TODO: NLiblet
355-
#if !NETSTANDARD1_1 && !NETSTANDARD1_3
355+
#if !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
356356
if ( !this._isInDynamicMethod && this._isDebuggable )
357357
{
358358
try
@@ -364,7 +364,7 @@ private LocalBuilder DeclareLocalCore( Type localType, string name )
364364
this._isInDynamicMethod = true;
365365
}
366366
}
367-
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
367+
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
368368
return result;
369369
}
370370

@@ -374,7 +374,7 @@ private LocalBuilder DeclareLocalCore( Type localType, string name, bool pinned
374374
var result = this._underlying.DeclareLocal( localType, pinned );
375375
this._localDeclarations.Add( result, name );
376376
// TODO: NLiblet
377-
#if !NETSTANDARD1_1 && !NETSTANDARD1_3
377+
#if !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
378378
if ( !this._isInDynamicMethod && this._isDebuggable )
379379
{
380380
try
@@ -386,7 +386,7 @@ private LocalBuilder DeclareLocalCore( Type localType, string name, bool pinned
386386
this._isInDynamicMethod = true;
387387
}
388388
}
389-
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
389+
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
390390
return result;
391391
}
392392
#endif // DEBUG
@@ -663,7 +663,7 @@ public void MarkLabel( Label label )
663663
#region -- Calli --
664664

665665
#if DEBUG
666-
#if !NETSTANDARD1_1 && !NETSTANDARD1_3
666+
#if !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
667667
/// <summary>
668668
/// Emit 'calli' instruction for indirect unmanaged function call.
669669
/// </summary>
@@ -710,7 +710,7 @@ public void EmitCalli( CallingConventions managedCallingConventions, Type return
710710
this._underlying.EmitCalli( OpCodes.Calli, managedCallingConventions, returnType, requiredParameterTypes, optionalParameterTypes );
711711
}
712712

713-
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
713+
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0
714714
#endif // DEBUG
715715
#endregion
716716
#endif // !SILVERLIGHT
@@ -809,7 +809,7 @@ public void EmitTailCallVirt( MethodInfo target )
809809
this.EmitRet();
810810
}
811811

812-
#if !SILVERLIGHT
812+
#if !SILVERLIGHT && !NETSTANDARD2_0
813813
/// <summary>
814814
/// Emit 'calli' instruction for indirect unmanaged function call as tail call.
815815
/// </summary>
@@ -867,7 +867,7 @@ public void EmitTailCalli( CallingConventions managedCallingConventions, Type re
867867
this.EmitCalli( managedCallingConventions, returnType, requiredParameterTypes, optionalParameterTypes );
868868
this.EmitRet();
869869
}
870-
#endif // SILVERLIGHT
870+
#endif // SILVERLIGHT && !NETSTANDARD2_0
871871
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
872872
#endif // DEBUG
873873

src/MsgPack/Serialization/SerializerDebugging.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#region -- License Terms --
1+
#region -- License Terms --
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2010-2016 FUJIWARA, Yusuke and contributors
5+
// Copyright (C) 2010-2017 FUJIWARA, Yusuke and contributors
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -203,6 +203,7 @@ public static void FlushTraceData()
203203
}
204204

205205
#if !NETSTANDARD1_3
206+
#if !NETSTANDARD2_0
206207
[ThreadStatic]
207208
private static AssemblyBuilder _assemblyBuilder;
208209

@@ -239,6 +240,7 @@ public static void PrepareDump()
239240
_moduleBuilder =
240241
_assemblyBuilder.DefineDynamicModule( "ExpressionTreeSerializerLogics", "ExpressionTreeSerializerLogics.dll", true );
241242
}
243+
#endif // !NETSTANDARD2_0
242244

243245
#if !FERATURE_CONCURRENT
244246
private static volatile DependentAssemblyManager _dependentAssemblyManager = DependentAssemblyManager.Default;
@@ -313,6 +315,7 @@ public static bool OnTheFlyCodeGenerationEnabled
313315
set { _onTheFlyCodeDomEnabled = value; }
314316
}
315317

318+
#if !NETSTANDARD2_0
316319
/// <summary>
317320
/// Creates the new type builder for the serializer.
318321
/// </summary>
@@ -345,15 +348,18 @@ public static void Dump()
345348
}
346349
#endif // !NET35
347350
}
351+
#endif // !NETSTANDARD2_0
348352

349353
/// <summary>
350354
/// Resets debugging states.
351355
/// </summary>
352356
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "For unit testing" )]
353357
public static void Reset()
354358
{
359+
#if !NETSTANDARD2_0
355360
_assemblyBuilder = null;
356361
_moduleBuilder = null;
362+
#endif // !NETSTANDARD2_0
357363
_dumpEnabled = false;
358364

359365
if ( _ilTraceWriter != null )
@@ -463,4 +469,4 @@ public static void SetCodeCompiler( CodeCompiler codeCompiler )
463469
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
464470
#endif // DEBUG
465471
}
466-
}
472+
}

0 commit comments

Comments
 (0)