Table of Contents

Class UseComparerAttribute

Namespace
Nerdbank.MessagePack
Assembly
Nerdbank.MessagePack.dll

Specifies a comparer to be used for the keyed collections on the decorated member.

[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter)]
public class UseComparerAttribute : Attribute
Inheritance
UseComparerAttribute
Inherited Members

Examples

The following snippet demonstrates a common pattern for properly using this attribute.

Notice how the comparer is specified both by attribute (which influences deserialized instances) and in the property initializer (which influences new instantiations created by user code).

Constructors

UseComparerAttribute(Type)

Initializes a new instance of the UseComparerAttribute class with the specified comparer type.

public UseComparerAttribute(Type comparerType)

Parameters

comparerType Type

The type of the comparer to be used. This type must implement the IComparer<T> or IEqualityComparer<T> interface, as appropriate for the decorated collection.

UseComparerAttribute(Type, string)

Initializes a new instance of the UseComparerAttribute class with the specified comparer source type and member name.

public UseComparerAttribute(Type comparerSource, string memberName)

Parameters

comparerSource Type

The type that provides the comparer.

memberName string

The name of the member within the comparerSource type that is used to obtain the comparer. The member must be a public property, and may be a static or an instance member. If an instance member, the comparerSource type must have a public default constructor.

Properties

ComparerType

Gets the type that provides the comparer to be used for the decorated member.

public Type ComparerType { get; }

Property Value

Type

MemberName

Gets the name of the member on ComparerType that provides the comparer, if applicable.

public string? MemberName { get; }

Property Value

string

Remarks

If null, the ComparerType itself is the comparer.