MsgPack.Serialization.DefaultConcreteTypeRepository Class Reference

Repository of known concrete collection type for abstract collection type. More...

Public Member Functions

Type Get (Type abstractCollectionType)
 Gets the default type for the collection. More...
 
void Register (Type abstractCollectionType, Type defaultCollectionType)
 Registers the default type of the collection. More...
 
bool Unregister (Type abstractCollectionType)
 Unregisters the default type of the collection. More...
 

Detailed Description

Repository of known concrete collection type for abstract collection type.

Member Function Documentation

◆ Get()

Type MsgPack.Serialization.DefaultConcreteTypeRepository.Get ( Type  abstractCollectionType)

Gets the default type for the collection.

Parameters
abstractCollectionTypeType of the abstract collection.
Returns
Type of default concrete collection. If concrete collection type of abstractCollectionType , then returns null.
Exceptions
System.ArgumentNullExceptionabstractCollectionType is null.

By default, following types are registered:

Abstract Collection Type Concrete Default Collection Type
IEnumerable<T> List<T>
ICollection<T> List<T>
ISet{T} (.NET 4 or lator) HashSet<T>
IList<T> List<T>
IDictionary<TKey,TValue> Dictionary<TKey,TValue>
IEnumerable List<T> of MessagePackObject.
ICollection List<T> of MessagePackObject.
IList List<T> of MessagePackObject.
IDictionary MessagePackObjectDictionary

◆ Register()

void MsgPack.Serialization.DefaultConcreteTypeRepository.Register ( Type  abstractCollectionType,
Type  defaultCollectionType 
)

Registers the default type of the collection.

Parameters
abstractCollectionTypeType of the abstract collection.
defaultCollectionTypeDefault concrete type of the abstractCollectionType .
Exceptions
System.ArgumentNullExceptionabstractCollectionType is null. Or defaultCollectionType is null.
System.ArgumentExceptionabstractCollectionType is not collection type. Or defaultCollectionType is abstract class or interface. Or defaultCollectionType is open generic type but abstractCollectionType is closed generic type. Or defaultCollectionType is closed generic type but abstractCollectionType is open generic type. Or defaultCollectionType does not have same arity for abstractCollectionType . Or defaultCollectionType is not assignable to abstractCollectionType or the constructed type from defaultCollectionType will not be assignable to the constructed type from abstractCollectionType .

If you want to overwrite default type for collection interfaces, you can use this method. Note that this method only supports collection interface, that is subtype of the IEnumerable interface. <note> If you register invalid type for defaultCollectionType , then runtime exception will be occurred. For example, you register IEnumerable<T> of Char and String pair, but it will cause runtime error. </note>

See also
Get

◆ Unregister()

bool MsgPack.Serialization.DefaultConcreteTypeRepository.Unregister ( Type  abstractCollectionType)

Unregisters the default type of the collection.

Parameters
abstractCollectionTypeType of the abstract collection.
Returns
true if default collection type is removed successfully; otherwise, false.

The documentation for this class was generated from the following file:
  • MsgPackSources/Serialization/DefaultConcreteTypeRepository.cs