Skip to content

Commit 1d40840

Browse files
committed
Fix MPS.Create() behavior for Xamarin/iOS.
1 parent 3904dd9 commit 1d40840

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

src/MsgPack/Serialization/AutoMessagePackSerializer`1.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public AutoMessagePackSerializer(
4444

4545
if ( serializer != null )
4646
{
47-
// For MessagePack.Create compatibility.
47+
// For MessagePack.Create compatibility.
48+
// Required for built-in types.
4849
this._underlying = serializer;
4950
return;
5051
}

src/MsgPack/Serialization/MessagePackSerializer.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,12 @@ public static MessagePackSerializer<T> Get<T>( SerializationContext context, obj
206206

207207
internal static MessagePackSerializer<T> CreateInternal<T>( SerializationContext context )
208208
{
209+
#if !XAMIOS && !XAMDROID && !UNITY
210+
Contract.Ensures( Contract.Result<MessagePackSerializer<T>>() != null );
211+
#endif // !XAMIOS && !XAMDROID && !UNITY
209212
#if XAMIOS || XAMDROID || UNITY
210-
return context.GetSerializer<T>();
213+
return CreateReflectionInternal<T>( context );
211214
#else
212-
213-
Contract.Ensures( Contract.Result<MessagePackSerializer<T>>() != null );
214-
215-
//Func<SerializationContext, SerializerBuilder<T>> builderProvider;
216215
ISerializerBuilder<T> builder;
217216
#if NETFX_CORE || WINDOWS_PHONE
218217
builder = new ExpressionTreeSerializerBuilder<T>();
@@ -331,7 +330,7 @@ public static IMessagePackSingleObjectSerializer Create( Type targetType, Serial
331330
#endif // !UNITY
332331

333332
#if XAMIOS || XAMDROID || UNITY
334-
return context.GetSerializer( targetType );
333+
return CreateReflectionInternal( context, targetType );
335334
#else
336335
// MPS.Create should always return new instance, and creator delegate should be cached for performance.
337336
#if NETFX_CORE
@@ -553,6 +552,15 @@ internal static IMessagePackSingleObjectSerializer CreateReflectionInternal( Ser
553552

554553
internal static MessagePackSerializer<T> CreateReflectionInternal<T>( SerializationContext context )
555554
{
555+
var serializer = context.Serializers.Get<T>( context );
556+
557+
if ( serializer != null )
558+
{
559+
// For MessagePack.Create compatibility.
560+
// Required for built-in types.
561+
return serializer;
562+
}
563+
556564
var traits = typeof( T ).GetCollectionTraits();
557565
switch ( traits.CollectionType )
558566
{

0 commit comments

Comments
 (0)