Skip to content

Commit 8b4908d

Browse files
committed
Fix build error in net35/Unity projects.
1 parent 16668ae commit 8b4908d

21 files changed

Lines changed: 385 additions & 64 deletions

src/MsgPack/ReflectionAbstractions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ public KeyValuePair<Type, object> GetTypedValue()
381381
}
382382
#endif // SILVERLIGHT
383383

384-
#if NETFX_40
384+
#if NETFX_35 || NETFX_40 || UNITY
385385
public static Delegate CreateDelegate( this MethodInfo source, Type delegateType )
386386
{
387387
return Delegate.CreateDelegate( delegateType, source );
388388
}
389-
#endif // NETFX_40
389+
#endif // NETFX_35 || NETFX_40 || UNITY
390390

391391
public static bool GetHasDefaultValue( this ParameterInfo source )
392392
{

src/MsgPack/Serialization/MessagePackSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ internal static MessagePackSerializer<T> CreateInternal<T>( SerializationContext
212212
Contract.Ensures( Contract.Result<MessagePackSerializer<T>>() != null );
213213
#endif // !XAMIOS && !XAMDROID && !UNITY
214214

215-
#if DEBUG
215+
#if DEBUG && !UNITY
216216
SerializerDebugging.TraceEvent(
217217
"SerializationContext::CreateInternal<{0}>(@{1}, {2})",
218218
typeof( T ),
219219
context.GetHashCode(),
220220
schema == null ? "null" : schema.DebugString
221221
);
222222

223-
#endif // DEBUG
223+
#endif // DEBUG && !UNITY
224224
Type concreteType = null;
225225

226226
if ( typeof( T ).GetIsAbstract() || typeof( T ).GetIsInterface() )

src/MsgPack/Serialization/PolymorphismSchema.Internals.cs

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
using System;
2424
using System.Collections.Generic;
25+
#if !NETFX_35 && !UNITY
2526
using System.Diagnostics.Contracts;
27+
#endif // !NETFX_35 && !UNITY
2628
using System.Globalization;
2729
using System.Linq;
2830
using System.Reflection;
@@ -44,72 +46,49 @@ partial class PolymorphismSchema
4446
/// ForPolymorphicObject( Type targetType )
4547
/// </summary>
4648
internal static readonly MethodInfo ForPolymorphicObjectTypeEmbeddingMethod =
47-
FromExpression.ToMethod( ( Type targetType ) => ForPolymorphicObject( targetType ) );
49+
typeof( PolymorphismSchema ).GetMethod( "ForPolymorphicObject", new[] { typeof( Type ) } );
4850

4951
/// <summary>
5052
/// ForPolymorphicObject( Type targetType, IDictionary{byte, Type} codeTypeMapping )
5153
/// </summary>
5254
internal static readonly MethodInfo ForPolymorphicObjectCodeTypeMappingMethod =
53-
FromExpression.ToMethod(
54-
( Type targetType, IDictionary<byte, Type> codeTypeMapping ) => ForPolymorphicObject( targetType, codeTypeMapping )
55-
);
55+
typeof( PolymorphismSchema ).GetMethod( "ForPolymorphicObject", new[] { typeof( Type ), typeof( IDictionary<byte, Type> ) } );
5656

5757
/// <summary>
5858
/// ForContextSpecifiedCollection( Type targetType, PolymorphismSchema itemsSchema )
5959
/// </summary>
6060
internal static readonly MethodInfo ForContextSpecifiedCollectionMethod =
61-
FromExpression.ToMethod(
62-
( Type targetType, PolymorphismSchema itemsSchema ) => ForContextSpecifiedCollection( targetType, itemsSchema )
63-
);
61+
typeof( PolymorphismSchema ).GetMethod( "ForContextSpecifiedCollection", new[] { typeof( Type ), typeof( PolymorphismSchema ) } );
6462

6563
/// <summary>
6664
/// ForPolymorphicCollection( Type targetType, PolymorphismSchema itemsSchema )
6765
/// </summary>
6866
internal static readonly MethodInfo ForPolymorphicCollectionTypeEmbeddingMethod =
69-
FromExpression.ToMethod(
70-
( Type targetType, PolymorphismSchema itemsSchema ) => ForPolymorphicCollection( targetType, itemsSchema )
71-
);
67+
typeof( PolymorphismSchema ).GetMethod( "ForPolymorphicCollection", new[] { typeof( Type ), typeof( PolymorphismSchema ) } );
7268

7369
/// <summary>
7470
/// ForPolymorphicCollection( Type targetType, IDictionary{byte, Type} codeTypeMapping, PolymorphismSchema itemsSchema )
7571
/// </summary>
7672
internal static readonly MethodInfo ForPolymorphicCollectionCodeTypeMappingMethod =
77-
FromExpression.ToMethod(
78-
( Type targetType, IDictionary<byte, Type> codeTypeMapping, PolymorphismSchema itemsSchema ) =>
79-
ForPolymorphicCollection( targetType, codeTypeMapping, itemsSchema )
80-
);
73+
typeof( PolymorphismSchema ).GetMethod( "ForPolymorphicCollection", new[] { typeof( Type ), typeof( IDictionary<byte, Type> ), typeof( PolymorphismSchema ) } );
8174

8275
/// <summary>
8376
/// ForContextSpecifiedDictionary( Type targetType, PolymorphismSchema keysSchema, PolymorphismSchema valuesSchema )
8477
/// </summary>
8578
internal static readonly MethodInfo ForContextSpecifiedDictionaryMethod =
86-
FromExpression.ToMethod(
87-
( Type targetType, PolymorphismSchema keysSchema, PolymorphismSchema valuesSchema ) =>
88-
ForContextSpecifiedDictionary( targetType, keysSchema, valuesSchema )
89-
);
79+
typeof( PolymorphismSchema ).GetMethod( "ForContextSpecifiedDictionary", new[] { typeof( Type ), typeof( PolymorphismSchema ), typeof( PolymorphismSchema ) } );
9080

9181
/// <summary>
9282
/// ForPolymorphicDictionary( Type targetType, PolymorphismSchema keysSchema, PolymorphismSchema valuesSchema )
9383
/// </summary>
9484
internal static readonly MethodInfo ForPolymorphicDictionaryTypeEmbeddingMethod =
95-
FromExpression.ToMethod(
96-
( Type targetType, PolymorphismSchema keysSchema, PolymorphismSchema valuesSchema ) =>
97-
ForPolymorphicDictionary( targetType, keysSchema, valuesSchema )
98-
);
85+
typeof( PolymorphismSchema ).GetMethod( "ForPolymorphicDictionary", new[] { typeof( Type ), typeof( PolymorphismSchema ), typeof( PolymorphismSchema ) } );
9986

10087
/// <summary>
10188
/// ForPolymorphicDictionary( Type targetType, IDictionary{byte, Type} codeTypeMapping, PolymorphismSchema keysSchema, PolymorphismSchema valuesSchema )
10289
/// </summary>
10390
internal static readonly MethodInfo ForPolymorphicDictionaryCodeTypeMappingMethod =
104-
FromExpression.ToMethod(
105-
( Type targetType,
106-
IDictionary<byte, Type> codeTypeMapping,
107-
PolymorphismSchema keysSchema,
108-
PolymorphismSchema valuesSchema
109-
) =>
110-
ForPolymorphicDictionary( targetType, codeTypeMapping, keysSchema, valuesSchema )
111-
);
112-
91+
typeof( PolymorphismSchema ).GetMethod( "ForPolymorphicDictionary", new[] { typeof( Type ), typeof( IDictionary<byte, Type> ), typeof( PolymorphismSchema ), typeof( PolymorphismSchema ) } );
11392

11493
#if !WINDOWS_PHONE && !NETFX_35 && !UNITY
11594
/// <summary>
@@ -123,7 +102,7 @@ PolymorphismSchema valuesSchema
123102

124103
internal static readonly ConstructorInfo CodeTypeMapConstructor =
125104
typeof( Dictionary<,> ).MakeGenericType( typeof( byte ), typeof( Type ) )
126-
.GetConstructor( new [] { typeof( int ) } );
105+
.GetConstructor( new[] { typeof( int ) } );
127106

128107
internal static readonly MethodInfo AddToCodeTypeMapMethod =
129108
typeof( Dictionary<,> ).MakeGenericType( typeof( byte ), typeof( Type ) )
@@ -223,7 +202,7 @@ internal static PolymorphismSchema Create(
223202
#if !UNITY
224203
SerializingMember? memberMayBeNull
225204
#else
226-
SerializingMember memberMayBeNull
205+
SerializingMember memberMayBeNull
227206
#endif // !UNITY
228207
)
229208
{
@@ -278,7 +257,7 @@ SerializingMember memberMayBeNull
278257
return Default;
279258
}
280259

281-
return
260+
return
282261
new PolymorphismSchema(
283262
member.Member.GetMemberValueType(),
284263
table.Member.PolymorphismType,
@@ -352,19 +331,25 @@ private struct TypeTable
352331
public readonly TypeTableEntry Member;
353332
public readonly TypeTableEntry CollectionItem;
354333
public readonly TypeTableEntry DictionaryKey;
334+
#if !WINDOWS_PHONE && !NETFX_35 && !UNITY
355335
public readonly IList<TypeTableEntry> TupleItems;
336+
#endif // !WINDOWS_PHONE && !NETFX_35 && !UNITY
356337

357338
private TypeTable(
358339
TypeTableEntry member,
359340
TypeTableEntry collectionItem,
360-
TypeTableEntry dictionaryKey,
361-
IList<TypeTableEntry> tupleItems
341+
TypeTableEntry dictionaryKey
342+
#if !WINDOWS_PHONE && !NETFX_35 && !UNITY
343+
, IList<TypeTableEntry> tupleItems
344+
#endif // !WINDOWS_PHONE && !NETFX_35 && !UNITY
362345
)
363346
{
364347
this.Member = member;
365348
this.CollectionItem = collectionItem;
366349
this.DictionaryKey = dictionaryKey;
350+
#if !WINDOWS_PHONE && !NETFX_35 && !UNITY
367351
this.TupleItems = tupleItems;
352+
#endif // !WINDOWS_PHONE && !NETFX_35 && !UNITY
368353
}
369354

370355
public static TypeTable Create( SerializationContext context, MemberInfo member )
@@ -373,15 +358,19 @@ public static TypeTable Create( SerializationContext context, MemberInfo member
373358
new TypeTable(
374359
TypeTableEntry.Create( context, member, PolymorphismTarget.Member ),
375360
TypeTableEntry.Create( context, member, PolymorphismTarget.CollectionItem ),
376-
TypeTableEntry.Create( context, member, PolymorphismTarget.DictionaryKey ),
377-
TypeTableEntry.CreateTupleItems( context, member )
361+
TypeTableEntry.Create( context, member, PolymorphismTarget.DictionaryKey )
362+
#if !WINDOWS_PHONE && !NETFX_35 && !UNITY
363+
, TypeTableEntry.CreateTupleItems( context, member )
364+
#endif // !WINDOWS_PHONE && !NETFX_35 && !UNITY
378365
);
379366
}
380367
}
381368

382369
private sealed class TypeTableEntry
383370
{
371+
#if !WINDOWS_PHONE && !NETFX_35 && !UNITY
384372
private static readonly TypeTableEntry[] EmptyEntries = new TypeTableEntry[ 0 ];
373+
#endif // !WINDOWS_PHONE && !NETFX_35 && !UNITY
385374

386375
private readonly Dictionary<byte, Type> _knownTypeMapping = new Dictionary<byte, Type>();
387376

@@ -422,6 +411,7 @@ var attribute in
422411
return result;
423412
}
424413

414+
#if !WINDOWS_PHONE && !NETFX_35 && !UNITY
425415
public static TypeTableEntry[] CreateTupleItems( SerializationContext context, MemberInfo member )
426416
{
427417
if ( !TupleItems.IsTuple( member.GetMemberValueType() ) )
@@ -443,6 +433,7 @@ var attribute in
443433

444434
return result;
445435
}
436+
#endif // !WINDOWS_PHONE && !NETFX_35 && !UNITY
446437

447438
private void Interpret( SerializationContext context, IPolymorphicHelperAttribute attribute, string memberName, int tupleItemNumber )
448439
{
@@ -470,14 +461,14 @@ private void Interpret( SerializationContext context, IPolymorphicHelperAttribut
470461
}
471462
}
472463

473-
#if DEBUG && !UNITY
464+
#if DEBUG && !NETFX_35 && !UNITY
474465
Contract.Assert( attribute is IPolymorphicRuntimeTypeAttribute, attribute + " is IPolymorphicRuntimeTypeAttribute" );
475-
#endif // DEBUG && !UNITY
466+
#endif // DEBUG && !NETFX_35 && !UNITY
476467
if ( this._useTypeEmbedding )
477468
{
478-
#if DEBUG && !UNITY
469+
#if DEBUG && !NETFX_35 && !UNITY
479470
Contract.Assert( attribute.Target == PolymorphismTarget.TupleItem, attribute.Target + " == PolymorphismTarget.TupleItem" );
480-
#endif // DEBUG && !UNITY
471+
#endif // DEBUG && !NETFX_35 && !UNITY
481472
throw new SerializationException(
482473
String.Format(
483474
CultureInfo.CurrentCulture,

src/MsgPack/Serialization/ReflectionSerializers/ReflectionObjectMessagePackSerializer`1.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ namespace MsgPack.Serialization.ReflectionSerializers
3838
/// </summary>
3939
internal class ReflectionObjectMessagePackSerializer<T> : MessagePackSerializer<T>
4040
{
41+
private static readonly PropertyInfo DictionaryEntryKeyProperty = typeof( DictionaryEntry ).GetProperty( "Key" );
42+
private static readonly PropertyInfo DictionaryEntryValueProperty = typeof( DictionaryEntry ).GetProperty( "Value" );
43+
4144
private readonly Func<object, object>[] _getters;
4245
private readonly Action<object, object>[] _setters;
4346
private readonly MemberInfo[] _memberInfos;
@@ -293,8 +296,8 @@ private object UnpackMemberValue( object objectGraph, Unpacker unpacker, int ite
293296
var arguments = new object[ 2 ];
294297
foreach ( var item in source )
295298
{
296-
arguments[ 0 ] = Metadata._DictionaryEntry.Key.GetValue( item, null );
297-
arguments[ 1 ] = Metadata._DictionaryEntry.Value.GetValue( item, null );
299+
arguments[ 0 ] = DictionaryEntryKeyProperty.GetValue( item, null );
300+
arguments[ 1 ] = DictionaryEntryValueProperty.GetValue( item, null );
298301
traits.AddMethod.Invoke( destination, arguments );
299302
}
300303
break;

test/MsgPack.UnitTest.CodeDom.Net35/MsgPack.UnitTest.CodeDom.Net35.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
</Reference>
4545
<Reference Include="System" />
4646
<Reference Include="System.Core" />
47+
<Reference Include="System.Runtime.Serialization" />
4748
<Reference Include="System.Xml.Linq" />
4849
<Reference Include="System.Data.DataSetExtensions" />
4950
<Reference Include="System.Data" />

test/MsgPack.UnitTest.CodeDom/Serialization/ArrayCodeDomBasedAutoMessagePackSerializerTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
//
2323
#endregion -- License Terms --
2424

25+
#if UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_WII || UNITY_IPHONE || UNITY_ANDROID || UNITY_PS3 || UNITY_XBOX360 || UNITY_FLASH || UNITY_BKACKBERRY || UNITY_WINRT
26+
#define UNITY
27+
#endif
28+
2529
#pragma warning disable 3003
2630
using System;
2731
using System.Collections;
@@ -5310,6 +5314,7 @@ public void TestPolymorphicMemberTypeKnownType_Dict_DictObjectItselfReadOnlyColl
53105314
}
53115315
#endregion ------ KnownType.DictionaryTypes ------
53125316

5317+
#if !NETFX_35 && !UNITY
53135318
#region ------ KnownType.TupleTypes ------
53145319

53155320
[Test]
@@ -6572,6 +6577,7 @@ public void TestPolymorphicMemberTypeKnownType_Tuple_Tuple8AllPolymorphicReadOnl
65726577
}
65736578
}
65746579
#endregion ------ KnownType.TupleTypes ------
6580+
#endif // #if !NETFX_35 && !UNITY
65756581

65766582
#endregion ---- KnownType ----
65776583
#region ---- RuntimeType ----
@@ -9037,6 +9043,7 @@ public void TestPolymorphicMemberTypeRuntimeType_Dict_DictObjectItselfReadOnlyCo
90379043
}
90389044
#endregion ------ RuntimeType.DictionaryTypes ------
90399045

9046+
#if !NETFX_35 && !UNITY
90409047
#region ------ RuntimeType.TupleTypes ------
90419048

90429049
[Test]
@@ -10299,6 +10306,7 @@ public void TestPolymorphicMemberTypeRuntimeType_Tuple_Tuple8AllPolymorphicReadO
1029910306
}
1030010307
}
1030110308
#endregion ------ RuntimeType.TupleTypes ------
10309+
#endif // #if !NETFX_35 && !UNITY
1030210310

1030310311
#endregion ---- RuntimeType ----
1030410312

@@ -10320,7 +10328,9 @@ public void TestPolymorphicMemberTypeMixed_Success()
1032010328
target.DictionaryKnownValue = new Dictionary<string, FileSystemEntry> { { "Key", new FileEntry { Name = "File", Size = 1 } } };
1032110329
target.DictionaryKnownContainerRuntimeValue = new Dictionary<string, FileSystemEntry> { { "Key", new FileEntry { Name = "File", Size = 2 } } };
1032210330
target.DictionaryObjectRuntimeValue = new Dictionary<string, object> { { "Key", new FileEntry { Name = "File", Size = 3 } } };
10331+
#if !NETFX_35 && !UNITY
1032310332
target.Tuple = Tuple.Create<string, FileSystemEntry, FileSystemEntry, object>( "ABC", new FileEntry { Name = "File", Size = 1 }, new FileEntry { Name = "File", Size = 3 }, new FileEntry { Name = "File", Size = 3 } );
10333+
#endif // !NETFX_35 && !UNITY
1032410334
var serializer = context.GetSerializer<PolymorphicMemberTypeMixed>();
1032510335

1032610336
using ( var buffer = new MemoryStream() )
@@ -10355,8 +10365,10 @@ public void TestPolymorphicMemberTypeMixed_Success()
1035510365
Assert.That( result.DictionaryKnownContainerRuntimeValue, Is.InstanceOf( target.DictionaryKnownContainerRuntimeValue.GetType() ), "DictionaryKnownContainerRuntimeValue" );
1035610366
Assert.That( result.DictionaryObjectRuntimeValue, Is.EqualTo( target.DictionaryObjectRuntimeValue ), "DictionaryObjectRuntimeValue" );
1035710367
Assert.That( result.DictionaryObjectRuntimeValue, Is.InstanceOf( target.DictionaryObjectRuntimeValue.GetType() ), "DictionaryObjectRuntimeValue" );
10368+
#if !NETFX_35 && !UNITY
1035810369
Assert.That( result.Tuple, Is.EqualTo( target.Tuple ), "Tuple" );
1035910370
Assert.That( result.Tuple, Is.InstanceOf( target.Tuple.GetType() ), "Tuple" );
10371+
#endif // !NETFX_35 && !UNITY
1036010372
}
1036110373
}
1036210374

@@ -10388,7 +10400,9 @@ public void TestPolymorphicMemberTypeMixed_Null_Success()
1038810400
Assert.That( result.DictionaryKnownValue, Is.Null );
1038910401
Assert.That( result.DictionaryKnownContainerRuntimeValue, Is.Null );
1039010402
Assert.That( result.DictionaryObjectRuntimeValue, Is.Null );
10403+
#if !NETFX_35 && !UNITY
1039110404
Assert.That( result.Tuple, Is.Null );
10405+
#endif // !NETFX_35 && !UNITY
1039210406
}
1039310407
}
1039410408

@@ -10867,6 +10881,7 @@ public void TestInterfaceCollectionRuntimeType_Success()
1086710881
Assert.That( result.Value, Is.EquivalentTo( target.Value ) );
1086810882
}
1086910883
}
10884+
#if !NETFX_35 && !UNITY
1087010885
[Test]
1087110886
[Category( "PolymorphicSerialization" )]
1087210887
public void TestTupleAbstractType_Success()
@@ -10887,6 +10902,7 @@ public void TestTupleAbstractType_Success()
1088710902
Assert.That( result.Value, Is.InstanceOf( target.Value.GetType() ) );
1088810903
}
1088910904
}
10905+
#endif // !NETFX_35 && !UNITY
1089010906

1089110907
[Test]
1089210908
[Category( "PolymorphicSerialization" )]
@@ -10914,6 +10930,7 @@ public void TestAttribute_DuplicatedKnownDictionaryKey_Fail()
1091410930
var target = new DuplicatedKnownDictionaryKey();
1091510931
Assert.Throws<SerializationException>( ()=> context.GetSerializer<DuplicatedKnownDictionaryKey>() );
1091610932
}
10933+
#if !NETFX_35 && !UNITY
1091710934

1091810935
[Test]
1091910936
[Category( "PolymorphicSerialization" )]
@@ -10923,6 +10940,7 @@ public void TestAttribute_DuplicatedKnownTupleItem_Fail()
1092310940
var target = new DuplicatedKnownTupleItem();
1092410941
Assert.Throws<SerializationException>( ()=> context.GetSerializer<DuplicatedKnownTupleItem>() );
1092510942
}
10943+
#endif // !NETFX_35 && !UNITY
1092610944

1092710945
[Test]
1092810946
[Category( "PolymorphicSerialization" )]
@@ -10950,6 +10968,7 @@ public void TestAttribute_KnownAndRuntimeDictionaryKey_Fail()
1095010968
var target = new KnownAndRuntimeDictionaryKey();
1095110969
Assert.Throws<SerializationException>( ()=> context.GetSerializer<KnownAndRuntimeDictionaryKey>() );
1095210970
}
10971+
#if !NETFX_35 && !UNITY
1095310972

1095410973
[Test]
1095510974
[Category( "PolymorphicSerialization" )]
@@ -10959,6 +10978,7 @@ public void TestAttribute_KnownAndRuntimeTupleItem_Fail()
1095910978
var target = new KnownAndRuntimeTupleItem();
1096010979
Assert.Throws<SerializationException>( ()=> context.GetSerializer<KnownAndRuntimeTupleItem>() );
1096110980
}
10981+
#endif // !NETFX_35 && !UNITY
1096210982

1096310983
#endregion -- Polymorphism --
1096410984
[Test]

0 commit comments

Comments
 (0)