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
TypeThe 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
TypeThe type that provides the comparer.
memberName
stringThe 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, thecomparerSource
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
MemberName
Gets the name of the member on ComparerType that provides the comparer, if applicable.
public string? MemberName { get; }
Property Value
Remarks
If null, the ComparerType itself is the comparer.