AdapterHelper.CanonicalizeType Method

Namespace
Kampute.DocToolkit.Metadata.Adapters
Assembly
  • Kampute.DocToolkit.dll

Definition

Resolves the canonical form of a type.
public static Type CanonicalizeType(Type type)

Parameters

type Type
The type to canonicalize.

Returns

Type
A canonicalized version of the type if applicable; otherwise, the original type.

Remarks

This method addresses a specific .NET reflection behavior where accessing nested generic types through inheritance relationships (such as Type.BaseType or Type.GetInterfaces()) can return Type instances that are semantically equivalent to direct typeof results but are not reference-equal when using the default equality comparer.

When a nested generic type definition is accessed via inheritance, the returned Type instance may be incorrectly flagged as a constructed generic type despite having only generic parameters as type arguments. This leads to discrepancies in equality comparisons, especially when such types are used as keys in collections that rely on reference equality.