You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit fdb099d
Browse filesBrowse the repository at this point in the historyBrowse files
Make the polytype-middleware sample compile on every TFM
Use a downlevel null check, place the extension block in a top-level static class, and give the witness overload its own message.
Co-authored-by: Andrew Arnott <andrew@mysideoftheweb.com>
Copy file name to clipboardExpand all lines: skills/polytype-middleware/SKILL.md
+35-20Lines changed: 35 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,15 +38,19 @@ The SDK defines `NET` for .NET 5 and later. `net472` and `netstandard2.0` are `!
38
38
39
39
Friendly overloads only obtain a shape and forward. Real work takes `ITypeShape<T>` or `ITypeShapeProvider` and exists on every TFM, with no `#if`.
40
40
41
-
The sample is one method, `ShapeMiddleware.Process`. Copy this split for each operation. `IShapeable<T>`, `ITypeShape<T>`, and `TypeShapeResolver` come from PolyType. `PreferDotNetAlternativeApi` is an attribute the library defines so an analyzer can see the dynamic member.
41
+
The sample is one method, `ShapeMiddleware.Process`. Copy this split for each operation. `IShapeable<T>`, `ITypeShape<T>`, and `TypeShapeResolver` come from PolyType. `PreferDotNetAlternativeApi` is an attribute the library defines so an analyzer can see the dynamic member. Null checks throw `ArgumentNullException` directly. `ArgumentNullException.ThrowIfNull` is not in the `net472` or `netstandard2.0` reference assemblies. The `extension` block sits in a top-level static class. C# rejects that block at namespace scope.
`where T : IShapeable<T>` calls `T.GetTypeShape()`. That is the witness-free API for `[GenerateShape]` on `T`. `where TProvider : IShapeable<T>` calls `TProvider.GetTypeShape()`. That is the witness API for `[GenerateShapeFor<T>]`. `T` itself is not constrained on the witness member. The witness extension takes `TProvider` as a type argument only. It does not repeat `where TProvider : IShapeable<T>`.
105
+
`where T : IShapeable<T>` calls `T.GetTypeShape()`. That is the witness-free API for `[GenerateShape]` on `T`. `where TProvider : IShapeable<T>` calls `TProvider.GetTypeShape()`. That is the witness API for `[GenerateShapeFor<T>]`. `T` itself is not constrained on the witness member. The witness extension takes `TProvider` as a type argument only. It does not repeat `where TProvider : IShapeable<T>`. Its `PreferDotNetAlternativeApi` and `Obsolete` text names `TProvider`, the type that must provide the shape.
91
106
92
107
A caller whose type has `[GenerateShape]` writes `middleware.Process(value)` on modern .NET. A type the caller does not own, including a top-level array, needs a witness: `middleware.Process<ExternalType, Witness>(value)`. Passing an `ITypeShape<T>` or `ITypeShapeProvider` explicitly works on every TFM with no source generator: `middleware.Process(value, shape)`.
93
108
94
109
The first two calls compile on every TFM. On modern .NET they bind to the members declared on the type. On downlevel they bind to the extension, so the file needs the namespace import. State that in the remarks on the type.
95
110
96
-
A static operation uses the same split. Declare the constrained method on the type under `#if NET`. Put the unconstrained member in the extension block, on every TFM. Consumers need C# 14 (`LangVersion` 14) to call extension members, including when the project targets .NET Framework or .NET Standard. The runtime does not need to be modern. Guard the extension block from a documentation tool only when that tool cannot parse it.
111
+
A static operation uses the same split. Declare the constrained method on the type under `#if NET`. Put the unconstrained member in an `extension` block inside a top-level static class, on every TFM. Consumers need C# 14 (`LangVersion` 14) to call extension members, including when the project targets .NET Framework or .NET Standard. The runtime does not need to be modern. Guard the extension block from a documentation tool only when that tool cannot parse it.
97
112
98
113
When the dynamic member cannot be an extension because the type already has an instance method with those parameters, give the dynamic member a different name. A second instance method that differs only by the constraint is illegal. Keep the constrained member's name under `#if NET`, and compile the distinctly named dynamic member for every TFM with the same parameters and the same `#if NET` attributes.
0 commit comments