Skip to content

Commit f7ab2ec

Browse files
committed
Change attribute matching from type identity based to name based.
1 parent 4216dc9 commit f7ab2ec

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/MsgPack/Serialization/SerializationTarget.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ namespace MsgPack.Serialization
5050
/// </summary>
5151
internal class SerializationTarget
5252
{
53+
// Type names to avoid user who doesn't embed "message pack assembly's attributes" in their code directly.
54+
private static readonly string MessagePackMemberAttributeTypeName = typeof( MessagePackMemberAttribute ).FullName;
55+
private static readonly string MessagePackIgnoreAttributeTypeName = typeof( MessagePackIgnoreAttribute ).FullName;
56+
private static readonly string MessagePackDeserializationConstructorAttributeTypeName = typeof( MessagePackDeserializationConstructorAttribute ).FullName;
57+
58+
5359
public IList<SerializingMember> Members { get; private set; }
5460
public ConstructorInfo DeserializationConstructor { get; private set; }
5561
public bool IsConstructorDeserialization
@@ -177,7 +183,7 @@ private static IEnumerable<SerializingMember> GetTargetMembers( Type type )
177183
Contract.Assert( type != null, "type != null" );
178184

179185
var members = GetDistinctMembers( type );
180-
var filtered = members.Where( item => item.IsDefined( typeof( MessagePackMemberAttribute ) ) ).ToArray();
186+
var filtered = members.Where( item => item.GetCustomAttributesData().Any( a => a.GetAttributeType().FullName == MessagePackMemberAttributeTypeName ) ).ToArray();
181187

182188
if ( filtered.Length > 0 )
183189
{
@@ -197,7 +203,7 @@ private static IEnumerable<SerializingMember> GetAnnotatedMembersWithDuplication
197203
{
198204
var duplicated =
199205
filtered.FirstOrDefault(
200-
member => member.IsDefined( typeof( MessagePackIgnoreAttribute ) )
206+
member => member.GetCustomAttributesData().Any( a => a.GetAttributeType().FullName == MessagePackIgnoreAttributeTypeName )
201207
);
202208

203209
if ( duplicated != null )
@@ -357,7 +363,7 @@ private static ConstructorInfo FindDeserializationConstructor( Type targetType )
357363

358364
private static IList<ConstructorInfo> FindExplicitDeserializationConstructors( IEnumerable<ConstructorInfo> construtors )
359365
{
360-
return construtors.Where( ctor => ctor.IsDefined( typeof( MessagePackDeserializationConstructorAttribute ) ) ).ToArray();
366+
return construtors.Where( ctor => ctor.GetCustomAttributesData().Any( a => a.GetAttributeType().FullName == MessagePackDeserializationConstructorAttributeTypeName ) ).ToArray();
361367
}
362368

363369
private static SerializationException NewTypeCannotBeSerializedException( Type targetType )

0 commit comments

Comments
 (0)