Skip to content

Commit bc17220

Browse files
committed
Fix Unity build error.
1 parent 11c2a32 commit bc17220

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/MsgPack/ReflectionAbstractions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public static ConstructorInfo GetRuntimeConstructor( this Type source, Type[] pa
254254
#endif // NETSTANDARD1_1 || NETSTANDARD1_3
255255
}
256256

257-
#if NETFX_35 || NETFX_40 || SILVERLIGHT
257+
#if NETFX_35 || NETFX_40 || SILVERLIGHT || UNITY
258258
public static Delegate CreateDelegate( this MethodInfo source, Type delegateType )
259259
{
260260
return Delegate.CreateDelegate( delegateType, source );
@@ -265,7 +265,7 @@ public static Delegate CreateDelegate( this MethodInfo source, Type delegateType
265265
return Delegate.CreateDelegate( delegateType, target, source );
266266
}
267267

268-
#endif // NETFX_35 || NETFX_40 || SILVERLIGHT
268+
#endif // NETFX_35 || NETFX_40 || SILVERLIGHT || UNITY
269269

270270
#if NETSTANDARD1_1 || NETSTANDARD1_3
271271
public static MethodInfo GetMethod( this Type source, string name )

src/MsgPack/Serialization/EnumMessagePackSerializer`1.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ ICustomizableEnumSerializer ICustomizableEnumSerializer.GetCopyAs( EnumSerializa
282282
internal abstract class UnityEnumMessagePackSerializer : NonGenericMessagePackSerializer, ICustomizableEnumSerializer
283283
{
284284
private readonly Type _underlyingType;
285+
private readonly Dictionary<object, string> _serializationMapping;
286+
private readonly Dictionary<string, object> _deserializationMapping;
285287
private EnumSerializationMethod _serializationMethod; // not readonly -- changed in cloned instance in GetCopyAs()
286288

287289
protected UnityEnumMessagePackSerializer( SerializationContext ownerContext, Type targetType, EnumSerializationMethod serializationMethod )
@@ -296,9 +298,9 @@ protected UnityEnumMessagePackSerializer( SerializationContext ownerContext, Typ
296298

297299
this._serializationMethod = serializationMethod;
298300
this._underlyingType = Enum.GetUnderlyingType( targetType );
299-
var members = Enum.GetValues( typeof( TEnum ) ) as TEnum[];
300-
this._serializationMapping = new Dictionary<TEnum, string>( members.Length );
301-
this._deserializationMapping = new Dictionary<string, TEnum>( members.Length );
301+
var members = Enum.GetValues(targetType ) as object[];
302+
this._serializationMapping = new Dictionary<object, string>( members.Length );
303+
this._deserializationMapping = new Dictionary<string, object>( members.Length );
302304
foreach ( var member in members )
303305
{
304306
var asString = ownerContext.EnumSerializationOptions.SafeNameTransformer( member.ToString() );
@@ -336,7 +338,7 @@ protected internal sealed override object UnpackFromCore( Unpacker unpacker )
336338
{
337339
var asString = unpacker.LastReadData.AsString();
338340

339-
TEnum result;
341+
object result;
340342
if ( !this._deserializationMapping.TryGetValue( asString, out result ) )
341343
{
342344
// May be undefined value which should be numeric, or PacakCasing.

src/MsgPack/Serialization/EnumSerializationOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public Func<string, string> NameTransformer
118118
set
119119
{
120120
#if NO_THREADING_VOLATILE
121-
this._enumNameTransformer = value;
121+
this._nameTransformer = value;
122122
#else
123123
Volatile.Write( ref this._nameTransformer, value );
124124
#endif

src/MsgPack/Serialization/SerializerDebugging.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public static void TraceEmitEvent( string format, params object[] args )
146146

147147
Tracer.Emit.TraceEvent( Tracer.EventType.DefineType, Tracer.EventId.DefineType, format, args );
148148
}
149+
#endif // !AOT && !SILVERLIGHT
149150

150151
/// <summary>
151152
/// Traces the polymorphic schema event.
@@ -156,14 +157,17 @@ public static void TraceEmitEvent( string format, params object[] args )
156157

157158
public static void TracePolimorphicSchemaEvent( string format, MemberInfo memberInfo, PolymorphismSchema schema )
158159
{
160+
#if !AOT && !SILVERLIGHT
159161
if ( !_traceEnabled )
160162
{
161163
return;
162164
}
163165

164166
Tracer.Emit.TraceEvent( Tracer.EventType.PolimorphicSchema, Tracer.EventId.PolimorphicSchema, format, memberInfo, schema == null ? "(null)" : schema.DebugString );
167+
#endif // !AOT && !SILVERLIGHT
165168
}
166169

170+
#if !AOT && !SILVERLIGHT
167171
/// <summary>
168172
/// Flushes the trace data.
169173
/// </summary>

0 commit comments

Comments
 (0)