Skip to content

Commit c210cd6

Browse files
committed
Fix [NonSerialized] is ignored in some platform.
This fix change [NonSerialized] attribute check from CustomAttributeData based to FieldAttributes based. This is required because nonserialized attribute is NOT custom attribute, it is IL attribute, so some implementation does not return CustomAttributeData for such "non-custom" attributes.
1 parent 88d05a4 commit c210cd6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,9 @@ Release 1.0.0-rc1 2017-12-17
745745
* Fix MessagePackObject.UnderlyingType reports wrong type for ext types. Part of #269.
746746
This bug also caused misleading error message for incompatible type conversion.
747747
* Fix exceptions thrown by MessagePackObject.AsBinary()/AsString() reports internal type name. Part of #269.
748+
749+
Release 1.0.0
750+
751+
BUG FIXES
752+
* [NonSerialized] attribute does not effect in Mono based platform including Unity.
753+

src/MsgPack/Serialization/SerializationTarget.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,23 @@ private static IEnumerable<SerializingMember> GetPublicUnpreventedMembers( Membe
466466
.Select( data => data.GetAttributeType().FullName )
467467
.Any( attr =>
468468
attr == "MsgPack.Serialization.MessagePackIgnoreAttribute"
469-
|| attr == "System.NonSerializedAttribute"
470469
|| attr == "System.Runtime.Serialization.IgnoreDataMemberAttribute"
471470
)
471+
&& !IsNonSerializedField( member )
472472
).Select( member => new SerializingMember( member, new DataMemberContract( member ) ) );
473473
}
474474

475+
private static bool IsNonSerializedField( MemberInfo member )
476+
{
477+
var asField = member as FieldInfo;
478+
if( asField == null )
479+
{
480+
return false;
481+
}
482+
483+
return ( asField.Attributes & FieldAttributes.NotSerialized ) != 0;
484+
}
485+
475486
private static ConstructorInfo FindDeserializationConstructor( SerializationContext context, Type targetType, out ConstructorKind constructorKind )
476487
{
477488
var constructors = targetType.GetConstructors().ToArray();

0 commit comments

Comments
 (0)