Allow type formatters to match by interface, base class, and generic type definition (fixes #644) - #680
Open
NoTh0ughts wants to merge 1 commit into
Conversation
NoTh0ughts
force-pushed
the
feature/hierarchical-type-formatters
branch
from
July 27, 2026 15:04
bd1b789 to
ddff637
Compare
…type definition Previously, AddTypeFormatter/TypeFormatter<T> only matched a value if its exact runtime type was registered, which made it impossible to reuse a formatter for an interface, a base class, or an open generic type definition (e.g. List<>). Resolution now falls back, in order, to the generic type definition, the implemented interfaces (and their generic definitions), and the base classes (and their generic definitions), with resolved lookups cached per runtime type. A new AddTypeFormatter(Type, ITypeFormatter) overload lets a formatter be registered for an open generic type definition, which can't be expressed as a type argument to AddTypeFormatter<T>. Fixes allure-framework#644
NoTh0ughts
force-pushed
the
feature/hierarchical-type-formatters
branch
from
July 27, 2026 15:06
ddff637 to
c3118ab
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Fixes #644.
AddTypeFormatter/TypeFormatter<T>only matched a value if its exactruntime type was registered (
value.GetType() == typeof(T)). That made itimpossible to reuse one formatter for an interface, a base class, or an
open generic type definition (e.g.
List<>), and made it hard to format3rd-party types that are inaccessible at compile time but implement a
public interface.
What changed
generic type definition → the interfaces it implements → their generic
definitions → its base classes → their generic definitions. Resolved
lookups are cached per runtime type and invalidated on new registrations
(
HierarchicalTypeFormatterLookup).AllureLifecycle.AddTypeFormatter(Type, ITypeFormatter)to registera formatter for an open generic type definition (
typeof(List<>)), whichcan't be expressed as a type argument to
AddTypeFormatter<T>.AllureLifecycle.TypeFormatterskeeps itsIReadOnlyDictionary<Type, ITypeFormatter>shape, so no existing call sites needed to change.Checklist