Morphir.Myriad.SystemTextJson.Annotations
0.5.0-alpha.4
Prefix Reserved
dotnet add package Morphir.Myriad.SystemTextJson.Annotations --version 0.5.0-alpha.4
NuGet\Install-Package Morphir.Myriad.SystemTextJson.Annotations -Version 0.5.0-alpha.4
<PackageReference Include="Morphir.Myriad.SystemTextJson.Annotations" Version="0.5.0-alpha.4" />
<PackageVersion Include="Morphir.Myriad.SystemTextJson.Annotations" Version="0.5.0-alpha.4" />
<PackageReference Include="Morphir.Myriad.SystemTextJson.Annotations" />
paket add Morphir.Myriad.SystemTextJson.Annotations --version 0.5.0-alpha.4
#r "nuget: Morphir.Myriad.SystemTextJson.Annotations, 0.5.0-alpha.4"
#:package Morphir.Myriad.SystemTextJson.Annotations@0.5.0-alpha.4
#addin nuget:?package=Morphir.Myriad.SystemTextJson.Annotations&version=0.5.0-alpha.4&prerelease
#tool nuget:?package=Morphir.Myriad.SystemTextJson.Annotations&version=0.5.0-alpha.4&prerelease
Morphir.Myriad.SystemTextJson.Annotations
Attributes and options for Morphir.Myriad.SystemTextJson, a Myriad plugin that generates trim-safe and Native AOT-safe System.Text.Json converters and contexts for F# records, unions and enums at build time.
This package has no dependency and targets netstandard2.0. Nothing in it runs: the generator reads the attributes from the F# source at build time.
open Morphir.Myriad.SystemTextJson
[<JsonUnion(BaseEncoding = (JsonUnionEncoding.InternalTag ||| JsonUnionEncoding.NamedFields), TagName = "kind")>]
type Shape =
| [<JsonName "circle">] Circle of radius: float
| [<JsonName "square">] Square of side: float
| Attribute | Use |
|---|---|
JsonUnion |
The encoding of one union: base encoding and flags, tag and fields names, naming. |
JsonRecord |
The member rules of one record: naming, skippable options, unknown members, null fields. |
JsonName |
The JSON name of a case or field. More names are accepted when reading. |
JsonParsedValue |
A type that is written as text and read only through its parser. |
JsonIgnoreType |
Leave a type out of the context. |
JsonDefaultValue |
A string, Boolean or numeric literal for an absent record member. |
JsonDefaultEmpty |
An empty sequence or map for an absent member. |
JsonDefaultValueProvider |
A direct call to an accessible static method with no arguments, returning the field's type. |
JsonDefaultJson |
An explicit JSON-literal default read through the generated field codec. |
JsonOmitEmpty |
Leave an empty record collection out on writing. |
JsonOmitDefault |
Leave a Boolean record field out on writing when it equals its JsonDefaultValue. |
JsonVersionAlias |
Read one exact legacy member/version pair and normalize it to the current form. |
JsonKnownPaths |
Require every critical path in a string collection to match the exact allowlist. |
Scalar strings are ordinary values, without JSON quoting. Decimal and domain defaults can use JsonDefaultValueProvider(typeof<Defaults>, nameof Defaults.Create); provider code runs only for an absent member at deserialization, and the generated call is checked by the F# compiler. It does not use reflection. Each field can declare only one default. Explicit null retains the field's normal rules.
The generator also supports System.Text.Json's JsonPropertyName and JsonExtensionData attributes; extension data requires a string-keyed JsonElement map record field. Unknown members are preserved beside the named members without a wrapper. New member rules are opt-in; unannotated fields retain their encodings and required-member checks.
The union encodings use the names and meanings of FSharp.SystemTextJson. See the Morphir.Myriad.SystemTextJson guide for the full reference.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Morphir.Myriad.SystemTextJson.Annotations:
| Package | Downloads |
|---|---|
|
Morphir.Mep
Shared Morphir Extension Protocol messages and transports |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.5.0-alpha.4 | 72 | 11/16/2026 |
| 0.5.0-alpha.3 | 91 | 11/14/2026 |
| 0.5.0-alpha.2 | 92 | 11/13/2026 |
| 0.5.0-alpha.1 | 88 | 11/13/2026 |
| 0.4.0-alpha.5 | 86 | 11/13/2026 |
| 0.4.0-alpha.4 | 82 | 11/10/2026 |
| 0.4.0-alpha.3 | 86 | 11/9/2026 |
| 0.4.0-alpha.2 | 53 | 11/8/2026 |
### Added
- The C# frontend of `morphir compile`: `morphir-dotnet.csharp` reads C# 15 source files in process, with Roslyn, in every offering. It lowers the C# dialect of the model (static classes and namespaces as modules, records and closed records as types, switch expressions as matches) to the current IR, and refuses code outside the subset with located diagnostics (`csharp.unsupported_*`).
- Passes: `transform` extensions that change a model between a frontend and a backend. `morphir extension list` shows them with their stage; `morphir generate` and `morphir compile` run them and report the applications under `passes` with `--json`. The first built-in pass, `morphir-dotnet.csharp.admission`, runs the checks of the C# backend before it. See [the middle end](docs/content/docs/pipeline/middle-end.md).
- `morphir generate` upgrades a classic model to the current IR when the backend reads the current IR only. The C# backend reads the current IR only, so `--target csharp` upgrades a classic model and runs the admission pass on it. `morphir extension list` shows the IR versions `4` and `4.0.0` for `morphir.csharp`.
- The C# backend writes local recursion: a tail call becomes a `while` loop, and any other recursive binding a local function. `List.filter`, `List.filterMap` and `List.foldl` map to `Morphir.SDK.CSharp`.
- `Morphir.SDK.CSharp` accepts plain C# records and plain C# unions in `Basics.Equal`, hashing and its collections. Equality and hashing use no reflection, so they work under Native AOT: a value outside the SDK kinds uses its own `Equals` and `GetHashCode`, and a delegate in code that people write compares by reference, as in .NET.
- `Morphir.SDK.CSharp` has generic `Basics` overloads for `T : INumber<T>` (`Add`, `Subtract`, `Multiply`, `Negate`, `Abs`, `Clamp`, `Power`) with checked arithmetic, and `List<T>` implements `IComparable<List<T>>` with the Morphir order.
- The C# backend writes generic functions over `comparable` (`where T : IComparable<T>`) and `number` (`where T : INumber<T>`), and checks the type at each call. The class of a type variable comes from the IR carrier, the `extensions` of its type attributes (`{"morphir-dotnet": {"classes": [...]}}`), else from the first word of its name. See [C# generation](docs/content/docs/backends/csharp/_index.md#generic-functions).
- The C# frontend writes the class of a type parameter in that carrier, from its .NET constraints (`IEquatable<T>`, `IEqualityOperators<T, T, bool>`, `IComparable<T>`, `IComparisonOperators<T, T, bool>`, `INumber<T>`) or from its uses in the body. On values of a type parameter, `a.Equals(b)` and `EqualityComparer<T>.Default.Equals(a, b)` become `Basics.equal`, and `a.CompareTo(b)` and `Comparer<T>.Default.Compare(a, b)` become `Basics.compare` matched to `-1`, `0` and `1`, with the ordinal order of the SDK.
- The C# frontend reads C# 15 unions. `union Shape(Circle, Rect)` is a custom type with the constructors `Circle` and `Rect`, each with the case type as its one argument `value`. A conversion to the union, `new Shape(circle)` and a cast apply the constructor; `Circle c`, `Circle(var r)` and `Rect { W: var w }` on a union are constructor patterns; `s is Circle` is a match that gives a `Bool`; `a.Equals(b)` on two unions is `Basics.equal`. A union that cannot convert is refused: a case with no name (`csharp.unsupported_union_case`), a member (`csharp.unsupported_union_member`), a case that another union of the module also has (`csharp.name_collision`), and code that reaches the state with no case: `default` (`csharp.unsupported_union_default`), a `null` arm (`csharp.unsupported_union_null`), `Value` (`csharp.unsupported_union_value`) and `IUnion` (`csharp.unsupported_union_interface`).
- The C# analyzer rule `MORPHIR1009` (`csharp.unsupported_abstract_record`) reports an older encoding of a sum type: an `abstract record` that is not `closed`, such as one with a private constructor and nested `sealed record` cases. `morphir compile` refuses it with the same code, message and range. A `closed record` and a union are not reported.
- `Morphir.Lang.CSharp.CodeFixes`: a Roslyn code fix for `MORPHIR1009` that changes an older sum type encoding to a `closed record` with the same cases and fields ("Change to a closed record"). It uses the Workspaces layer of Roslyn, so only an IDE loads it: no host, `Morphir.Lang.CSharp` or `Morphir.Tooling` references it, and a build test checks the restored closure of each host. The fix never changes a union. The page of the C# frontend documents the two sum type forms, the older encoding and the fix, and tests compile its examples.
- C# handling options in code: `[MorphirEquality(FloatEquality.Ieee)]` (assembly, type, property or positional parameter), `[MorphirEmit(Traversal = ..., TailRecursion = ...)]` and `[MorphirLoop(...)]` (assembly, class or method), and `[MorphirValueClass(...)]` on a type parameter, in the attribute assembly of `Morphir.Lang.CSharp`. A project needs no `morphir.toml` for them. The nearest attribute wins, and the command line wins over each attribute. The C# frontend writes a backend option into the model, in the `extensions` of type attributes under `morphir-dotnet.options`, so `morphir generate` on the model file applies it and writes the attribute back. A field with plain equality in a type with IEEE equality compares as plain C# does.
- The `[codegen.csharp]` table of `morphir.toml` has the keys of the C# backend: `extension`, `namespace`, `language_version`, `profile`, `traversal`, `tail_recursion` and `float_equality`. `morphir generate` and `morphir compile --target` give each key except `extension` to the backend, below the attributes of the model, and `--option` wins over each key. The C# backend accepts `--option traversal=loopfunctional`, `tail-recursion=looplocal-function` and `float-equality=clrieee`. A malformed value fails with exit code 2 before any file is written.
- `[frontend.csharp]` in `morphir.toml` has the key `loop_lowering` (`traversal`, `recursion`), the configuration carrier of `[MorphirLoop]`. An attribute on the method, the type or the assembly wins over the key. The table is closed, so a key that the C# frontend does not know, or a bad value, fails when the configuration loads, with exit code 2. `morphir compile` gives the scalar keys of the `[frontend.<language>]` table of the selected frontend (except `extension` and `project_file`, with `-` for `_`) to the frontend as extra members of the MEP `CompileOptions`; `CompileRequest.ExtraOptions` carries them, and the MEP frontend adapter writes them to a guest. See [C# handling options](docs/content/docs/backends/csharp/options.md#frontend-options-in-morphirtoml).
- The C# admission rule `MORPHIR1010` (`csharp.unsupported_non_partial_equality`) refuses a record or a union with IEEE equality from an attribute that is not `partial`.
- Packages `Morphir.Lang.CSharp` and `Morphir.MiddleEnd`. `Morphir.Lang.CSharp` has the C# frontend, the C# passes and the C# backend, with its analyzer and attribute assemblies in `lib/`. `Morphir.MiddleEnd` has the IR upgrade steps, the semantic node addresses and the transform contract. `Morphir.Tooling` depends on both. The package also has the build integration: see the entries of the source generator and the MSBuild target.
- `CSharpPipeline.Generate` in `Morphir.Lang.CSharp`: the pipeline function of C# generation. It reads the bytes of a model, upgrades a classic model, runs the C# passes and the backend, and has no file or process access. It gives the paths and bytes of `morphir generate --target csharp`, and diagnostics with no files for a model that is not valid. `Morphir.Lang.CSharp` also targets `netstandard2.0` for it.
- The Roslyn source generator `Morphir.Lang.CSharp.Generator` (`netstandard2.0`): it runs the pipeline function on each `*.morphir.json` additional file of a project and adds the C# to the compilation. A model that is not valid gives the error `MORPHIR2001` with the model file and the reason; two models that write one file with different text give `MORPHIR2003`. `MorphirCSharpNamespace` sets the namespace. It compiles against Roslyn 5.12.0, the compiler of .NET SDK 11.0.100.
- The build integration of the package `Morphir.Lang.CSharp`: `analyzers/dotnet/cs` has the source generator and the admission analyzers with their closure, and `build/` has the props and targets. A project with `<MorphirGenerateCSharpFiles>true</MorphirGenerateCSharpFiles>` gets the opt-in MSBuild target: it writes the generated files into `$(IntermediateOutputPath)morphir/csharp/` before the compilation and compiles them, and the source generator does nothing. The package sets `LangVersion` 15, and a build with a .NET SDK older than 11.0.100 stops with the error `MORPHIR2010`, which names the SDK that it needs. The project can still target a lower framework.
- The source generator and the MSBuild target write the polyfill file `Morphir.Polyfill.g.cs` only for a target framework below `net11.0`. A library and an application that each have their own polyfill file build with no warning, and a `switch` in the application on a `union` or a `closed record` of the library is exhaustive.
- `scripts/csharp-sdk-matrix.sh`, a check in the `test` job of the Development workflow: a consumer of the packed `Morphir.Lang.CSharp` generates with .NET SDK 11.0.100, and SDK 10.0.100 and 10.0.403 stop with `MORPHIR2010`. The generator compiles against Roslyn 5.12.0, so it does not load in the compiler of SDK 10 (`CS9057`).
- The page [C# generation in a build](docs/content/docs/backends/csharp/build-integration.md): the source generator, the MSBuild target, their settings and diagnostics, the package layout and the support matrix. Visual Studio, Rider and VS Code are not tested. A packages-lane scenario runs the commands of the page as written.
- The C# frontend lowers loops (LOP-1). A `foreach` that adds to an empty `List<T>` becomes `List.map`, `List.filter` or `List.filterMap`; a `foreach` that changes locals becomes `List.foldl`, with a tuple state for two or more locals; a `while`, `do` or `for` loop, and a `foreach` with `break`, `return` or `continue`, becomes a `LetRecursion` whose parameters are the changed locals. One loop recognizer in `Morphir.Lang.CSharp.Analyzers` decides for the analyzer and the frontend, so the IDE and `morphir compile` accept and refuse the same loops.
- `Morphir.SDK.CSharp` `List<T>` has `Select`, `Where` and `Aggregate`, the functional forms of `List.map`, `List.filter` and `List.foldl`, beside `FilterMap`. They come before the methods of LINQ, so each call on an SDK list gives an SDK value.
- The C# frontend reads the functional forms as the IR of the loop forms: `Select` is `List.map`, `Where` is `List.filter`, `Aggregate` is `List.foldl` and `FilterMap` is `List.filterMap`, on LINQ and on an SDK list. `Where` then `Select` is `List.map` over `List.filter`. A lambda that only applies a function to its parameter is that function: `o => Notional(o)` is `notional`. Local functions next to each other are one `LetRecursion`. `Maybe<T>.Just` and `Maybe<T>.Nothing` are the constructors of `Maybe`.
- The C# backend has two profiles for the rows of the transform table, with the handling option `profile` (`--option profile=imperative`, the default, or `--option profile=functional`, or the key `profile` of `[codegen.csharp]`). The imperative profile writes a `foreach` that adds to a list for `List.map`, `List.filter` and `List.filterMap`, and a `foreach` with accumulator locals for `List.foldl`. The functional profile writes `Select`, `Where`, `FilterMap` and `Aggregate`. A tail-recursive `LetRecursion` that the code after it calls once is a `while` loop with state locals in each profile. The frontend reads the C# of each profile back to the same IR. See [C# generation](docs/content/docs/backends/csharp/_index.md#profiles).
- The loop options apply to loops: `[MorphirLoop(LoopLowering.Recursion)]` makes a fold a `LetRecursion` over the list, and `--option tail-recursion=local-function` (or `[MorphirEmit(TailRecursion = TailRecursionForm.LocalFunction)]`) writes a tail call as a call of a local recursive function. `--option traversal` selects the loop form or the functional form of one profile rule.
### Changed
- **BREAKING:** the C# backend is written on Roslyn and writes C# 15 only. `language-version=14` now fails with `unsupported-language`, and `language-version=15` is the default.
- **BREAKING:** the package `Morphir.CodeGeneration.CSharp` is removed. The package `Morphir.Lang.CSharp` replaces it: the API of the backend is `CSharpBackend.Generate` in `Morphir.Lang.CSharp.Emit`.
- **BREAKING:** the shape of the generated C# changed. A module with only types is a namespace, and a module with values is a `static class` named after the module (no `...Module` suffix), with its types nested in it. A custom type is a `closed record` with `sealed record` cases, or a `union` of wrapper cases (no `abstract class` with nested cases). Records have the equality of plain C#: `NaN` is equal to `NaN`. The Morphir members (`MorphirEquals` and the others) are written only when you ask for IEEE equality. A file `Morphir.Polyfill.g.cs` carries the runtime types that `closed` and `union` need below .NET 11. See [C# generation](docs/content/docs/backends/csharp/_index.md).
- The Native AOT `morphir` links Roslyn for the C# frontend and backend.
- The C# backend refuses equality on a type that holds a function at generation time with `unsupported-equality`, also through a type variable, a field of a case or the record of a union case, and the message gives the path to the function type. A generic function over `appendable` or `compappend` is refused with `unsupported-appendable`.
- `MORPHIR1001` (`csharp.unsupported_loop`) refuses only a loop with no Morphir form, and its message gives the reason: the loop writes a field, a property or an array element, reads a field that can change, changes no local and builds no list, or builds a list in a form that has no list function. A change of a local in a loop is the state of the loop, so `MORPHIR1002` does not report it.
- The C# admission rules (`MORPHIR1001` and the others) cannot be suppressed: `#pragma warning disable`, `.editorconfig` and `NoWarn` do not hide them, and the new rule `MORPHIR1008` (`csharp.unsupported_suppression`) refuses a `SuppressMessage` attribute that names a rule. A refused construct cannot become a model, so `morphir compile` refuses it in every case.
### Fixed
- The C# frontend gives the model that the C# means, or it refuses the C#. Named arguments bind to their parameters; a record value gets each field by name, and an object initializer sets a field again; a switch on an enum gives constructor patterns; the variable of a case field does not capture a parameter; a generic call has the types of the call. `switch` statements whose sections return and tuple deconstruction declarations are lowered. A record value that leaves out a field, an abstract record, record inheritance, a record member that is not a field and a static member that is not a method or a constant are refused. Two constructors of one module with one Morphir name give `csharp.name_collision`. The compilation has the implicit usings of an SDK project.
- The C# analyzer refuses a symbol from an assembly outside the fixed reference set, including NuGet packages with a `System` name, and no longer reports a deconstruction declaration as a mutation. `morphir compile` reports an analyzer failure (`AD0001`) as an error, gives a missing return a location in the document, and puts diagnostics in the same order on each run.
- The C# backend writes only the switch arms that can match, so a match on `True` and `False`, a repeated arm and a covered arm compile. A negative literal given to a wrapper case compiles. Two record aliases that share one C# record keep their field values. Functions of one `LetRecursion` that call each other only as their last step become one `while` loop with a state, so deep mutual recursion does not overflow the stack. The layout re-parse uses C# 15.
- The C# backend writes `Morphir.Polyfill.g.cs` into each output, with `IsExternalInit` (below .NET 5), `CompilerFeatureRequiredAttribute` (below .NET 7) and `UnionAttribute`, `IUnion` and `IsClosedTypeAttribute` (below .NET 11).
- The C# backend refuses with `name-collision`, and names both owners, when a case, a type, a value or a module class has the name of another in one namespace or static class. A value or a type with a name that ends in `Module` now generates. A wrapper custom type with private constructors, or with two constructors of the same C# type, is a `closed record` with sealed cases, not a `union`. A public module below a module with no module of its own between them is reachable.
- The C# backend generates a module that has a record alias and a wrapper case of the same name, such as the record `Circle` and the case `Circle Circle` of the union `Shape`. Before, a construction or a match of the case failed with `ambiguous-constructor`. A wrapper type (`union`) and a mixed type (`closed record`) come back from the generated C# through the C# frontend with the same IR.
- `generate --target csharp` stops before the backend with `transform.feature_remains` when an extensible record, a hole or a body that is not an expression remains after the passes. `compile --target` reports the passes before the backend in `generation.passes`, with their diagnostics, and one application list from the frontend output. An IR upgrade error names the address of the node that the current IR cannot hold. The application list names a node of the input for a rule that rewrites inside an earlier replacement, an upgrade chain pins each kept record to its output, and the passes report keeps the upgrade records when no pass ran.
- The C# frontend reads the C# that the C# backend writes: a call of `Morphir.SDK.CSharp.Decimal`, such as `Decimal.Mul(a, b)`, is the SDK function of the module `Decimal`, and `List<T>.FromEnumerable(new T[] { ... })` is a list value. Before, the frontend refused both with `csharp.unsupported_reference`, so a model with a decimal operation or a list did not come back from its generated C#.