Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions MsgPack/Formatters/TypeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ private static void BuildSerializeArrayBody(Type type, ILGenerator g, MemberInfo

// Value
g.Emit(OpCodes.Ldarg_0);
g.Emit(OpCodes.Ldarg_1);
// if it's a struct.. we handle it differently
// using the address of the argument and not its value.
if (type.IsValueType)
g.Emit(OpCodes.Ldarga_S, 1);
else
g.Emit(OpCodes.Ldarg_1);

g.EmitCall(OpCodes.Call, property.GetGetMethod(), null);
g.EmitCall(OpCodes.Call, serializer, null);
}
Expand Down Expand Up @@ -290,11 +296,11 @@ private static void BuildSerializeMapBody(Type type, ILGenerator g, DynamicArray

case PropertyInfo property:
{
var methodFieldSerializer = type == property.PropertyType
var methodPropertySerializer = type == property.PropertyType
? currentSerializer
: MsgPackRegistry.GetOrCreateSerializer(property.PropertyType);

if (methodFieldSerializer == null)
if (methodPropertySerializer == null)
throw new NotSupportedException($"Requested serializer for {type.Name}.{property.Name} of type {property.PropertyType} could not be found.");

// Key
Expand All @@ -304,9 +310,16 @@ private static void BuildSerializeMapBody(Type type, ILGenerator g, DynamicArray

// Value
g.Emit(OpCodes.Ldarg_0);
g.Emit(OpCodes.Ldarg_1);
// Same as above
// if it's a struct.. we handle it differently
// using the address of the argument and not its value.
if (type.IsValueType)
g.Emit(OpCodes.Ldarga_S, 1);
else
g.Emit(OpCodes.Ldarg_1);

g.EmitCall(OpCodes.Call, property.GetGetMethod(), null);
g.EmitCall(OpCodes.Call, methodFieldSerializer, null);
g.EmitCall(OpCodes.Call, methodPropertySerializer, null);
}
break;

Expand Down