Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregating ITypeShapeProvider #91

Closed
AArnott opened this issue Dec 19, 2024 · 1 comment · Fixed by #107
Closed

Aggregating ITypeShapeProvider #91

AArnott opened this issue Dec 19, 2024 · 1 comment · Fixed by #107

Comments

@AArnott
Copy link
Contributor

AArnott commented Dec 19, 2024

Consider an ITypeShapeProvider implementation that aggregates results from a list of other ITypeShapeProvider instances.
This aggregator would take a list of other instances and return the first shape from the list of providers that returns a non-null result.
It may include caching of the result for faster repeat calls.

This would enable combining multiple shape providers and querying them in a unified manner.
The scenario I'm thinking about is of an RPC system that may have access to several source generated ITypeShapeProvider instances, and may also want to fallback to the reflection-based ITypeShapeProvider when no source generated one is known.

Example usage

ITypeShapeProvider provider1 = ...;
ITypeShapeProvider provider2 = ...;
ITypeShapeProvider aggregatedProvider = new AggregatedTypeShapeProvider(new[] { provider1, provider2 });

var shape = aggregatedProvider.GetShape(typeof(MyType));
@eiriktsarpalis
Copy link
Owner

Here's the relevant concept in STJ: https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization.metadata.jsontypeinforesolver.combine?view=net-9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants