polytype-middleware
PolyType middleware APIs
A PolyType middleware library sits on PolyType.IShapeable<T> and ships one package to every target framework its consumers use. Modern .NET callers get a constrained, witness-free API. Downlevel callers (net472, netstandard2.0) still get a complete API, usually with a witness type parameter. Callers that still run on .NET 8 or .NET 9 use that downlevel surface.
Use the same shape for every friendly operation. The modern assembly is the downlevel surface plus the constrained members.
Why the members are split
IShapeable<T>.GetTypeShape() is a static abstract interface member. where T : IShapeable<T> compiles only in the modern assembly. That constraint is the witness-free API: the caller names T, and T supplies its own shape.
A generic constraint is not part of the method signature. Two methods in the same declaration space cannot differ only by where T : IShapeable<T>.
Keep two declarations with the same parameters:
- A member declared on the type, compiled only under
#if NET, with the constraint, forwarding toT.GetTypeShape()orTProvider.GetTypeShape(). - An extension member compiled for every TFM, with no
IShapeable<T>constraint, forwarding toTypeShapeResolver.ResolveDynamicOrThrow<T>()orResolveDynamicOrThrow<T, TProvider>().
Overload resolution prefers an applicable instance member over an extension. When T : IShapeable<T>, the constrained member wins. When the constraint is not met, the extension is still a candidate.