diff --git a/.github/workflows/build_nuget_dont_publish.yml b/.github/workflows/build_nuget_dont_publish.yml
index 5876aeb..7236ae5 100644
--- a/.github/workflows/build_nuget_dont_publish.yml
+++ b/.github/workflows/build_nuget_dont_publish.yml
@@ -8,27 +8,33 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
-
- - name: Setup .NET
- uses: actions/setup-dotnet@v1
- with:
- dotnet-version: |
- 10.0.x
- 9.0.x
- 8.0.x
-
- - name: Extract version from tag
- run: echo "VERSION=$(echo ${GITHUB_REF#refs/tags/v})" >> $GITHUB_ENV
-
- - name: Restore dependencies
- run: dotnet restore
-
- - name: Build
- run: dotnet build --no-restore -c Release
+ - uses: actions/checkout@v4
+
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: |
+ 11.0.x
+ 10.0.x
+
+ - name: Set version
+ shell: bash
+ run: |
+ VERSION="${{ github.ref_name }}"
+ VERSION="${VERSION#v}"
+ if [ -z "$VERSION" ] || [ "$VERSION" = "main" ]; then
+ VERSION="0.0.0-local"
+ fi
+ echo "VERSION=$VERSION" >> "$GITHUB_ENV"
+
+ - name: Restore dependencies
+ run: dotnet restore
+
+ - name: Build
+ run: dotnet build --no-restore -c Release
# - name: Test
# run: dotnet test --no-build
- - name: Pack
- run: dotnet pack --no-build -c Release -o nupkg -p:Version=${{ env.VERSION }}
+ - name: Pack
+ run: dotnet pack --no-build -c Release -o nupkg -p:Version=${{ env.VERSION }}
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index 30b5129..462e27e 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -26,9 +26,8 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
+ 11.0.x
10.0.x
- 9.0.x
- 8.0.x
- name: Restore dependencies
run: dotnet restore
diff --git a/.github/workflows/publish_nuget.yml b/.github/workflows/publish_nuget.yml
index d6dc934..f97eafa 100644
--- a/.github/workflows/publish_nuget.yml
+++ b/.github/workflows/publish_nuget.yml
@@ -7,33 +7,80 @@ on:
jobs:
build:
runs-on: ubuntu-latest
+ permissions:
+ contents: read
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
- - name: Setup .NET
- uses: actions/setup-dotnet@v1
- with:
- dotnet-version: |
- 10.0.x
- 9.0.x
- 8.0.x
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: |
+ 11.0.x
+ 10.0.x
- - name: Extract version from tag
- run: echo "VERSION=$(echo ${GITHUB_REF#refs/tags/v})" >> $GITHUB_ENV
+ - name: Extract version from tag
+ shell: bash
+ run: |
+ VERSION="${{ github.ref_name }}"
+ VERSION="${VERSION#v}"
+ echo "VERSION=$VERSION" >> "$GITHUB_ENV"
- - name: Restore dependencies
- run: dotnet restore
+ - name: Restore dependencies
+ run: dotnet restore
- - name: Build
- run: dotnet build --no-restore -c Release
+ - name: Build
+ run: dotnet build --no-restore -c Release
-# - name: Test
-# run: dotnet test --no-build
+ - name: Pack
+ run: dotnet pack --no-build -c Release -o nupkg -p:Version=${{ env.VERSION }}
- - name: Pack
- run: dotnet pack --no-build -c Release -o nupkg -p:Version=${{ env.VERSION }}
+ - name: Upload packages
+ uses: actions/upload-artifact@v4
+ with:
+ name: nuget-packages
+ path: nupkg/*
+ if-no-files-found: error
- - name: Publish
- run: dotnet nuget push "nupkg/*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
+ publish:
+ runs-on: ubuntu-latest
+ needs: build
+ permissions:
+ contents: read
+ id-token: write
+
+ steps:
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: |
+ 11.0.x
+ 10.0.x
+
+ - name: Download packages
+ uses: actions/download-artifact@v4
+ with:
+ name: nuget-packages
+ path: nupkg
+
+ - name: NuGet login (OIDC → temp API key)
+ uses: NuGet/login@v1
+ id: login
+ with:
+ user: ${{ secrets.NUGET_USER }}
+
+ - name: Publish package
+ id: publish_package
+ continue-on-error: true
+ run: dotnet nuget push "nupkg/*.nupkg" --skip-duplicate --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" -s https://api.nuget.org/v3/index.json
+
+ - name: Publish symbols
+ id: publish_symbols
+ continue-on-error: true
+ run: dotnet nuget push "nupkg/*.snupkg" --skip-duplicate --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" -s https://api.nuget.org/v3/index.json
+ - name: Warn about publish credential failure
+ if: steps.publish_package.outcome == 'failure' || steps.publish_symbols.outcome == 'failure'
+ run: |
+ echo "::warning::NuGet publish failed because the configured credential was rejected. The build completed successfully and the generated packages were uploaded as workflow artifacts for manual publishing after the NuGet credential is rotated."
diff --git a/Directory.Build.props b/Directory.Build.props
index 041da7c..756c63e 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,6 +1,6 @@
- net8.0;net9.0;net10.0
+ net10.0;net11.0
Library
enable
Latest
@@ -11,7 +11,7 @@
Domain Primitives
ALTA Software llc.
Copyright © 2024 ALTA Software llc.
- 8.1.3
+ 9.0.0
diff --git a/Directory.Packages.props b/Directory.Packages.props
index d3bc8ad..58f3588 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -7,14 +7,21 @@
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Examples/AltaSoft.DomainPrimitives.Demo/AltaSoft.DomainPrimitives.Demo.csproj b/Examples/AltaSoft.DomainPrimitives.Demo/AltaSoft.DomainPrimitives.Demo.csproj
index cef6361..65c4a3f 100644
--- a/Examples/AltaSoft.DomainPrimitives.Demo/AltaSoft.DomainPrimitives.Demo.csproj
+++ b/Examples/AltaSoft.DomainPrimitives.Demo/AltaSoft.DomainPrimitives.Demo.csproj
@@ -1,8 +1,7 @@
- net10.0
-
+ net10.0;net11.0
enable
enable
true
@@ -17,16 +16,21 @@
-
-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/Examples/DomainPrimitivesDemo/DomainPrimitivesDemo.csproj b/Examples/DomainPrimitivesDemo/DomainPrimitivesDemo.csproj
index 7065cfa..0cb16a1 100644
--- a/Examples/DomainPrimitivesDemo/DomainPrimitivesDemo.csproj
+++ b/Examples/DomainPrimitivesDemo/DomainPrimitivesDemo.csproj
@@ -1,15 +1,19 @@
- net10.0;net9.0
+ net10.0;net11.0
enable
true
1591
false
-
-
+
+
+
+
+
+
diff --git a/README.md b/README.md
index 49b37fd..aedd390 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# DomainPrimitives for C#
[](https://www.nuget.org/profiles/AltaSoft)
-[](https://dotnet.microsoft.com)
+[](https://dotnet.microsoft.com)
# Table of Contents
@@ -38,6 +38,16 @@ With `AltaSoft.DomainPrimitives`, experience an accelerated development process
## What's New
+### .NET 11 Support
+
+The library now targets `net10.0` and `net11.0`. Support for .NET 8 and .NET 9 has been dropped.
+
+* **Framework-specific dependencies:** Packages that ship separate builds per .NET version are resolved per target framework:
+ - `net10.0`: `Microsoft.AspNetCore.OpenApi` 10.x, `Microsoft.OpenApi` 2.x, `Swashbuckle.AspNetCore.SwaggerGen` 10.x
+ - `net11.0`: `Microsoft.AspNetCore.OpenApi` 11.x, `Microsoft.OpenApi` 3.x, `Swashbuckle.AspNetCore.SwaggerGen` 11.x
+* **OpenAPI Extensions:** `AltaSoft.DomainPrimitives.OpenApiExtensions` now targets both `net10.0` and `net11.0`.
+* **OpenAPI schema examples:** The `` XML doc value is now emitted into the generated `OpenApiHelper` as `OpenApiSchema.Examples` instead of the obsolete `Example` property. `AltaSoft.DomainPrimitives.SwaggerExtensions` now references `Microsoft.OpenApi` directly (latest 2.x on `net10.0`, latest 3.x on `net11.0`) so examples are also written for OpenAPI 3.0 documents.
+
### Flexible Date & Time Parsing / Deserialization
Parsing and deserialization for `DateOnly`, `DateTime`, `DateTimeOffset`, `TimeOnly`, and `TimeSpan` domain primitives has been significantly improved:
@@ -138,7 +148,7 @@ public readonly partial struct OrderNumber : IDomainValue { /* validation
## Getting Started
### Prerequisites
-* .NET 8 or higher
+* .NET 10 or higher
* NuGet Package Manager
### Installation
diff --git a/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs b/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs
index 5411ca7..8b965b0 100644
--- a/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs
+++ b/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs
@@ -109,7 +109,7 @@ void AddMapping()
if (!data.UnderlyingType.IsNumeric())
exampleValue = Quote(exampleValue);
- builder.Append("Example = JsonValue.Create(").Append(exampleValue).AppendLine("),");
+ builder.Append("Examples = [JsonValue.Create(").Append(exampleValue).AppendLine(")],");
}
}
diff --git a/src/AltaSoft.DomainPrimitives.OpenApiExtensions/AltaSoft.DomainPrimitives.OpenApiExtensions.csproj b/src/AltaSoft.DomainPrimitives.OpenApiExtensions/AltaSoft.DomainPrimitives.OpenApiExtensions.csproj
index d49b17f..d1d9aeb 100644
Binary files a/src/AltaSoft.DomainPrimitives.OpenApiExtensions/AltaSoft.DomainPrimitives.OpenApiExtensions.csproj and b/src/AltaSoft.DomainPrimitives.OpenApiExtensions/AltaSoft.DomainPrimitives.OpenApiExtensions.csproj differ
diff --git a/src/AltaSoft.DomainPrimitives.OpenApiExtensions/OpenApiOptionsExt.cs b/src/AltaSoft.DomainPrimitives.OpenApiExtensions/OpenApiOptionsExt.cs
index b9b15c1..6f6229f 100644
--- a/src/AltaSoft.DomainPrimitives.OpenApiExtensions/OpenApiOptionsExt.cs
+++ b/src/AltaSoft.DomainPrimitives.OpenApiExtensions/OpenApiOptionsExt.cs
@@ -38,7 +38,7 @@ internal void ApplyDomainPrimitiveSchemas(OpenApiSchema domainPrimitiveSchema, b
schemaToApply.Properties = domainPrimitiveSchema.Properties;
schemaToApply.Required = domainPrimitiveSchema.Required;
schemaToApply.Description = domainPrimitiveSchema.Description;
- schemaToApply.Example = domainPrimitiveSchema.Example;
+ schemaToApply.Examples = domainPrimitiveSchema.Examples;
schemaToApply.Enum = domainPrimitiveSchema.Enum;
schemaToApply.MinLength = domainPrimitiveSchema.MinLength;
schemaToApply.MaxLength = domainPrimitiveSchema.MaxLength;
diff --git a/src/AltaSoft.DomainPrimitives.SwaggerExtensions/AltaSoft.DomainPrimitives.SwaggerExtensions.csproj b/src/AltaSoft.DomainPrimitives.SwaggerExtensions/AltaSoft.DomainPrimitives.SwaggerExtensions.csproj
index 3606eba..b12c0a1 100644
Binary files a/src/AltaSoft.DomainPrimitives.SwaggerExtensions/AltaSoft.DomainPrimitives.SwaggerExtensions.csproj and b/src/AltaSoft.DomainPrimitives.SwaggerExtensions/AltaSoft.DomainPrimitives.SwaggerExtensions.csproj differ
diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/AltaSoft.DomainPrimitives.Generator.Tests.csproj b/tests/AltaSoft.DomainPrimitives.Generator.Tests/AltaSoft.DomainPrimitives.Generator.Tests.csproj
index bdf3a77..cb6705d 100644
--- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/AltaSoft.DomainPrimitives.Generator.Tests.csproj
+++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/AltaSoft.DomainPrimitives.Generator.Tests.csproj
@@ -1,7 +1,7 @@
- net10.0
+ $(DefaultTargetFrameworks)
enable
enable
diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/DomainPrimitiveGeneratorTest.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/DomainPrimitiveGeneratorTest.cs
index 4f2fc5d..ccf051b 100644
--- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/DomainPrimitiveGeneratorTest.cs
+++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/DomainPrimitiveGeneratorTest.cs
@@ -40,6 +40,41 @@ public static PrimitiveValidationResult Validate(string value)
return TestHelper.Verify(source, (_, x, _) => Assert.Equal(4, x.Count));
}
+ [Fact]
+ public Task StringValue_WithXmlExampleStringLengthAndPattern()
+ {
+ const string source = """
+ using AltaSoft.DomainPrimitives;
+
+ namespace AltaSoft.DomainPrimitives;
+
+ ///
+ /// A country code.
+ ///
+ /// GE
+ [StringLength(2, 2)]
+ [Pattern(@"[A-Z]{2}")]
+ public partial class CountryCode : IDomainValue
+ {
+ ///
+ public static PrimitiveValidationResult Validate(string value) => PrimitiveValidationResult.Ok;
+ }
+
+ ///
+ /// A positive amount.
+ ///
+ /// 42
+ public readonly partial struct PositiveAmount : IDomainValue
+ {
+ ///
+ public static PrimitiveValidationResult Validate(int value) => PrimitiveValidationResult.Ok;
+ }
+
+ """;
+
+ return TestHelper.Verify(source);
+ }
+
[Fact]
public Task StringValue_WithTransStringLengthAndPatternWithValidation()
{
diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#CountryCode.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#CountryCode.g.verified.cs
new file mode 100644
index 0000000..071e811
--- /dev/null
+++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#CountryCode.g.verified.cs
@@ -0,0 +1,336 @@
+//HintName: CountryCode.g.cs
+//------------------------------------------------------------------------------
+//
+// This code was generated by 'AltaSoft DomainPrimitives Generator'.
+// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#nullable enable
+
+#pragma warning disable CS8774 // Member must have a non-null value when exiting.
+#pragma warning disable CS0628 // New protected member declared in sealed type
+#pragma warning disable CS0612 // Type or member is obsolete
+#pragma warning disable CS0618 // Type or member is obsolete
+#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor
+#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
+#pragma warning disable IDE0290 // Use primary constructor
+
+using System;
+using System.Numerics;
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+using AltaSoft.DomainPrimitives;
+using System.Diagnostics.CodeAnalysis;
+using System.Text.Json.Serialization;
+using AltaSoft.DomainPrimitives.Converters;
+using System.ComponentModel;
+
+namespace AltaSoft.DomainPrimitives;
+
+[JsonConverter(typeof(CountryCodeJsonConverter))]
+[TypeConverter(typeof(CountryCodeTypeConverter))]
+[UnderlyingPrimitiveType(typeof(string))]
+[DebuggerDisplay("{_value}")]
+public partial class CountryCode : IEquatable
+ , IComparable
+ , IComparable
+ , IParsable
+ , IConvertible
+{
+ ///
+ public Type GetUnderlyingPrimitiveType() => typeof(string);
+ ///
+ public object GetUnderlyingPrimitiveValue() => (string)this;
+
+ private string _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(CountryCode));
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)]
+ private readonly string _value;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)]
+ private readonly bool _isInitialized;
+
+ ///
+ /// Initializes a new instance of the class by validating the specified value using static method.
+ ///
+ /// The value to be validated.
+ public CountryCode(string value) : this(value, true)
+ {
+ }
+
+ private CountryCode(string value, bool validate)
+ {
+ if (validate)
+ {
+ if (value.Length is < 2 or > 2)
+ throw InvalidDomainValueException.StringRangeException(typeof(CountryCode), value, 2, 2);
+
+ ValidateOrThrow(value);
+ }
+ _value = value;
+ _isInitialized = true;
+ }
+#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
+
+ ///
+ [Obsolete("Domain primitive cannot be created using empty Constructor", true)]
+ public CountryCode()
+ {
+ }
+#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
+
+ ///
+ /// Tries to create an instance of CountryCode from the specified value.
+ ///
+ /// The value to create CountryCode from
+ /// When this method returns, contains the created CountryCode if the conversion succeeded, or null if the conversion failed.
+ /// true if the conversion succeeded; otherwise, false.
+ public static bool TryCreate(string value, [NotNullWhen(true)] out CountryCode? result)
+ {
+ return TryCreate(value, out result, out _);
+ }
+
+ ///
+ /// Tries to create an instance of CountryCode from the specified value.
+ ///
+ /// The value to create CountryCode from
+ /// When this method returns, contains the created CountryCode if the conversion succeeded, or null if the conversion failed.
+ /// When this method returns, contains the error message if the conversion failed; otherwise, null.
+ /// true if the conversion succeeded; otherwise, false.
+ public static bool TryCreate(string value, [NotNullWhen(true)] out CountryCode? result, [NotNullWhen(false)] out string? errorMessage)
+ {
+ if (value.Length is < 2 or > 2)
+ {
+ result = null;
+ errorMessage = "String length is out of range 2..2";
+ return false;
+ }
+
+ var validationResult = Validate(value);
+ if (!validationResult.IsValid)
+ {
+ result = null;
+ errorMessage = validationResult.ErrorMessage;
+ return false;
+ }
+
+ result = new (value, false);
+ errorMessage = null;
+ return true;
+ }
+
+ ///
+ /// Validates the specified value and throws an exception if it is not valid.
+ ///
+ /// The value to validate
+ /// Thrown when the value is not valid.
+ public void ValidateOrThrow(string value)
+ {
+ var result = Validate(value);
+ if (!result.IsValid)
+ throw new InvalidDomainValueException(result.ErrorMessage, typeof(CountryCode), value);
+ }
+
+
+ ///
+ /// Gets the character at the specified index.
+ ///
+ public char this[int i]
+ {
+ get => _value[i];
+ }
+
+ ///
+ /// Gets the character at the specified index.
+ ///
+ public char this[Index index]
+ {
+ get => _value[index];
+ }
+
+ ///
+ /// Gets the substring by specified range.
+ ///
+ public string this[Range range]
+ {
+ get => _value[range];
+ }
+
+ ///
+ /// Gets the number of characters.
+ ///
+ /// The number of characters in underlying string value.
+ public int Length => _value.Length;
+
+ ///
+ /// Returns a substring of this string.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public string Substring(int startIndex, int length) => _value.Substring(startIndex, length);
+
+ ///
+ /// Returns a substring of this string.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public string Substring(int startIndex) => _value.Substring(startIndex);
+
+ ///
+ /// Checks if the specified value is contained within the current instance.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool Contains(string value) => _value.Contains(value);
+
+ ///
+ /// Determines whether a specified string is a prefix of the current instance.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool StartsWith(string value) => _value.StartsWith(value);
+
+ ///
+ /// Determines whether a specified string is a suffix of the current instance.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool EndsWith(string value) => _value.EndsWith(value);
+
+ ///
+ /// Returns the entire string as an array of characters.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public char[] ToCharArray() => _value.ToCharArray();
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public override bool Equals(object? obj) => obj is CountryCode other && Equals(other);
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool Equals(CountryCode? other)
+ {
+ if (other is null || !_isInitialized || !other._isInitialized)
+ return false;
+ return _value.Equals(other._value);
+ }
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator ==(CountryCode? left, CountryCode? right)
+ {
+ if (ReferenceEquals(left, right))
+ return true;
+ if (left is null || right is null)
+ return false;
+ return left.Equals(right);
+ }
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator !=(CountryCode? left, CountryCode? right) => !(left == right);
+
+ ///
+ public int CompareTo(object? obj)
+ {
+ if (obj is null)
+ return 1;
+
+ if (obj is CountryCode c)
+ return CompareTo(c);
+
+ throw new ArgumentException("Object is not a CountryCode", nameof(obj));
+ }
+
+ ///
+ public int CompareTo(CountryCode? other)
+ {
+ if (other is null || !other._isInitialized)
+ return 1;
+ if (!_isInitialized)
+ return -1;
+ return _value.CompareTo(other._value);
+ }
+
+ ///
+ /// Implicit conversion from (nullable) to (nullable)
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [return: NotNullIfNotNull(nameof(value))]
+ public static implicit operator CountryCode?(string? value) => value is null ? null : new(value);
+
+ ///
+ /// Implicit conversion from (nullable) to (nullable)
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [return: NotNullIfNotNull(nameof(value))]
+ public static implicit operator string?(CountryCode? value) => value is null ? null : (string?)value._valueOrThrow;
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static CountryCode Parse(string s, IFormatProvider? provider) => s;
+
+ ///
+ public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out CountryCode result)
+ {
+ if (s is null)
+ {
+ result = default;
+ return false;
+ }
+
+ return CountryCode.TryCreate(s, out result);
+ }
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public override int GetHashCode() => _valueOrThrow.GetHashCode();
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ TypeCode IConvertible.GetTypeCode() => ((IConvertible)(String)_valueOrThrow).GetTypeCode();
+
+ ///
+ bool IConvertible.ToBoolean(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToBoolean(provider);
+
+ ///
+ byte IConvertible.ToByte(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToByte(provider);
+
+ ///
+ char IConvertible.ToChar(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToChar(provider);
+
+ ///
+ DateTime IConvertible.ToDateTime(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToDateTime(provider);
+
+ ///
+ decimal IConvertible.ToDecimal(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToDecimal(provider);
+
+ ///
+ double IConvertible.ToDouble(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToDouble(provider);
+
+ ///
+ short IConvertible.ToInt16(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToInt16(provider);
+
+ ///
+ int IConvertible.ToInt32(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToInt32(provider);
+
+ ///
+ long IConvertible.ToInt64(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToInt64(provider);
+
+ ///
+ sbyte IConvertible.ToSByte(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToSByte(provider);
+
+ ///
+ float IConvertible.ToSingle(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToSingle(provider);
+
+ ///
+ string IConvertible.ToString(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToString(provider);
+
+ ///
+ object IConvertible.ToType(Type conversionType, IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToType(conversionType, provider);
+
+ ///
+ ushort IConvertible.ToUInt16(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToUInt16(provider);
+
+ ///
+ uint IConvertible.ToUInt32(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToUInt32(provider);
+
+ ///
+ ulong IConvertible.ToUInt64(IFormatProvider? provider) => ((IConvertible)(String)_valueOrThrow).ToUInt64(provider);
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public override string ToString() => _valueOrThrow.ToString();
+}
diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#CountryCodeJsonConverter.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#CountryCodeJsonConverter.g.verified.cs
new file mode 100644
index 0000000..357f35c
--- /dev/null
+++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#CountryCodeJsonConverter.g.verified.cs
@@ -0,0 +1,70 @@
+//HintName: CountryCodeJsonConverter.g.cs
+//------------------------------------------------------------------------------
+//
+// This code was generated by 'AltaSoft DomainPrimitives Generator'.
+// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#nullable enable
+
+#pragma warning disable CS8774 // Member must have a non-null value when exiting.
+#pragma warning disable CS0628 // New protected member declared in sealed type
+#pragma warning disable CS0612 // Type or member is obsolete
+#pragma warning disable CS0618 // Type or member is obsolete
+#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor
+#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
+#pragma warning disable IDE0290 // Use primary constructor
+
+using AltaSoft.DomainPrimitives;
+using System;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Globalization;
+using System.Text.Json.Serialization.Metadata;
+
+namespace AltaSoft.DomainPrimitives.Converters;
+
+///
+/// JsonConverter for
+///
+internal sealed class CountryCodeJsonConverter : JsonConverter
+{
+ ///
+ public override CountryCode Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ try
+ {
+ return JsonInternalConverters.StringConverter.Read(ref reader, typeToConvert, options)!;
+ }
+ catch (InvalidDomainValueException ex)
+ {
+ throw new JsonException(ex.Message);
+ }
+ }
+
+ ///
+ public override void Write(Utf8JsonWriter writer, CountryCode value, JsonSerializerOptions options)
+ {
+ JsonInternalConverters.StringConverter.Write(writer, (string)value, options);
+ }
+
+ ///
+ public override CountryCode ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ try
+ {
+ return JsonInternalConverters.StringConverter.ReadAsPropertyName(ref reader, typeToConvert, options)!;
+ }
+ catch (InvalidDomainValueException ex)
+ {
+ throw new JsonException(ex.Message);
+ }
+ }
+
+ ///
+ public override void WriteAsPropertyName(Utf8JsonWriter writer, CountryCode value, JsonSerializerOptions options)
+ {
+ JsonInternalConverters.StringConverter.WriteAsPropertyName(writer, (string)value, options);
+ }
+}
diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#CountryCodeTypeConverter.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#CountryCodeTypeConverter.g.verified.cs
new file mode 100644
index 0000000..c5daa65
--- /dev/null
+++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#CountryCodeTypeConverter.g.verified.cs
@@ -0,0 +1,46 @@
+//HintName: CountryCodeTypeConverter.g.cs
+//------------------------------------------------------------------------------
+//
+// This code was generated by 'AltaSoft DomainPrimitives Generator'.
+// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#nullable enable
+
+#pragma warning disable CS8774 // Member must have a non-null value when exiting.
+#pragma warning disable CS0628 // New protected member declared in sealed type
+#pragma warning disable CS0612 // Type or member is obsolete
+#pragma warning disable CS0618 // Type or member is obsolete
+#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor
+#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
+#pragma warning disable IDE0290 // Use primary constructor
+
+using AltaSoft.DomainPrimitives;
+using System;
+using System.ComponentModel;
+using System.Globalization;
+
+namespace AltaSoft.DomainPrimitives.Converters;
+
+///
+/// TypeConverter for
+///
+internal sealed class CountryCodeTypeConverter : StringConverter
+{
+ ///
+ public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
+ {
+ var result = base.ConvertFrom(context, culture, value);
+ if (result is null)
+ return null;
+ try
+ {
+ return new CountryCode((string)result);
+ }
+ catch (InvalidDomainValueException ex)
+ {
+ throw new FormatException("Cannot parse CountryCode", ex);
+ }
+ }
+}
diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#OpenApiHelper.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#OpenApiHelper.g.verified.cs
new file mode 100644
index 0000000..86ef169
--- /dev/null
+++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#OpenApiHelper.g.verified.cs
@@ -0,0 +1,73 @@
+//HintName: OpenApiHelper.g.cs
+//------------------------------------------------------------------------------
+//
+// This code was generated by 'AltaSoft DomainPrimitives Generator'.
+// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#nullable enable
+
+#pragma warning disable CS8774 // Member must have a non-null value when exiting.
+#pragma warning disable CS0628 // New protected member declared in sealed type
+#pragma warning disable CS0612 // Type or member is obsolete
+#pragma warning disable CS0618 // Type or member is obsolete
+#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor
+#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
+#pragma warning disable IDE0290 // Use primary constructor
+
+using AltaSoft.DomainPrimitives;
+using Microsoft.OpenApi;
+using System;
+using System.Collections.Frozen;
+using System.Collections.Generic;
+using System.Text.Json.Nodes;
+
+[assembly: AltaSoft.DomainPrimitives.DomainPrimitiveAssemblyAttribute]
+namespace generator_Test.Converters.Helpers;
+
+///
+/// Helper class providing methods to configure OpenApiSchema mappings for DomainPrimitive types of generator_Test
+///
+public static class OpenApiHelper
+{
+ ///
+ /// Mapping of DomainPrimitive types to OpenApiSchema definitions.
+ ///
+ ///
+ /// The Dictionary contains mappings for the following types:
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static FrozenDictionary Schemas = new Dictionary()
+ {
+ {
+ typeof(CountryCode),
+ new OpenApiSchema
+ {
+ Type = JsonSchemaType.String,
+ Title = "CountryCode",
+ Description = @"A country code.",
+ Examples = [JsonValue.Create("GE")],
+ MinLength = 2,
+ MaxLength = 2,
+ Pattern = "[A-Z]{2}"
+ }
+ },
+ {
+ typeof(PositiveAmount),
+ new OpenApiSchema
+ {
+ Type = JsonSchemaType.Integer,
+ Format = "int32",
+ Title = "PositiveAmount",
+ Description = @"A positive amount.",
+ Examples = [JsonValue.Create(42)]
+ }
+ }
+ }.ToFrozenDictionary();
+}
diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#PositiveAmount.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#PositiveAmount.g.verified.cs
new file mode 100644
index 0000000..bac84c5
--- /dev/null
+++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#PositiveAmount.g.verified.cs
@@ -0,0 +1,325 @@
+//HintName: PositiveAmount.g.cs
+//------------------------------------------------------------------------------
+//
+// This code was generated by 'AltaSoft DomainPrimitives Generator'.
+// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#nullable enable
+
+#pragma warning disable CS8774 // Member must have a non-null value when exiting.
+#pragma warning disable CS0628 // New protected member declared in sealed type
+#pragma warning disable CS0612 // Type or member is obsolete
+#pragma warning disable CS0618 // Type or member is obsolete
+#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor
+#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
+#pragma warning disable IDE0290 // Use primary constructor
+
+using System;
+using System.Numerics;
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+using AltaSoft.DomainPrimitives;
+using System.Diagnostics.CodeAnalysis;
+using System.Text.Json.Serialization;
+using AltaSoft.DomainPrimitives.Converters;
+using System.ComponentModel;
+
+namespace AltaSoft.DomainPrimitives;
+
+[JsonConverter(typeof(PositiveAmountJsonConverter))]
+[TypeConverter(typeof(PositiveAmountTypeConverter))]
+[UnderlyingPrimitiveType(typeof(int))]
+[DebuggerDisplay("{_value}")]
+public readonly partial struct PositiveAmount : IEquatable
+ , IComparable
+ , IComparable
+ , IAdditionOperators
+ , ISubtractionOperators
+ , IMultiplyOperators
+ , IDivisionOperators
+ , IModulusOperators
+ , IComparisonOperators
+ , IParsable
+ , IConvertible
+#if NET8_0_OR_GREATER
+ , IUtf8SpanFormattable
+#endif
+{
+ ///
+ public Type GetUnderlyingPrimitiveType() => typeof(int);
+ ///
+ public object GetUnderlyingPrimitiveValue() => (int)this;
+
+ private int _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(PositiveAmount));
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)]
+ private readonly int _value;
+ [DebuggerBrowsable(DebuggerBrowsableState.Never)]
+ private readonly bool _isInitialized;
+
+ ///
+ /// Initializes a new instance of the class by validating the specified value using static method.
+ ///
+ /// The value to be validated.
+ public PositiveAmount(int value) : this(value, true)
+ {
+ }
+
+ private PositiveAmount(int value, bool validate)
+ {
+ if (validate)
+ {
+ ValidateOrThrow(value);
+ }
+ _value = value;
+ _isInitialized = true;
+ }
+
+ ///
+ [Obsolete("Domain primitive cannot be created using empty Constructor", true)]
+ public PositiveAmount()
+ {
+ }
+
+ ///
+ /// Tries to create an instance of PositiveAmount from the specified value.
+ ///
+ /// The value to create PositiveAmount from
+ /// When this method returns, contains the created PositiveAmount if the conversion succeeded, or null if the conversion failed.
+ /// true if the conversion succeeded; otherwise, false.
+ public static bool TryCreate(int value, [NotNullWhen(true)] out PositiveAmount? result)
+ {
+ return TryCreate(value, out result, out _);
+ }
+
+ ///
+ /// Tries to create an instance of PositiveAmount from the specified value.
+ ///
+ /// The value to create PositiveAmount from
+ /// When this method returns, contains the created PositiveAmount if the conversion succeeded, or null if the conversion failed.
+ /// When this method returns, contains the error message if the conversion failed; otherwise, null.
+ /// true if the conversion succeeded; otherwise, false.
+ public static bool TryCreate(int value, [NotNullWhen(true)] out PositiveAmount? result, [NotNullWhen(false)] out string? errorMessage)
+ {
+ var validationResult = Validate(value);
+ if (!validationResult.IsValid)
+ {
+ result = null;
+ errorMessage = validationResult.ErrorMessage;
+ return false;
+ }
+
+ result = new (value, false);
+ errorMessage = null;
+ return true;
+ }
+
+ ///
+ /// Validates the specified value and throws an exception if it is not valid.
+ ///
+ /// The value to validate
+ /// Thrown when the value is not valid.
+ public void ValidateOrThrow(int value)
+ {
+ var result = Validate(value);
+ if (!result.IsValid)
+ throw new InvalidDomainValueException(result.ErrorMessage, typeof(PositiveAmount), value);
+ }
+
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public override bool Equals(object? obj) => obj is PositiveAmount other && Equals(other);
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool Equals(PositiveAmount other)
+ {
+ if (!_isInitialized || !other._isInitialized)
+ return false;
+ return _value.Equals(other._value);
+ }
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator ==(PositiveAmount left, PositiveAmount right) => left.Equals(right);
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator !=(PositiveAmount left, PositiveAmount right) => !(left == right);
+
+ ///
+ public int CompareTo(object? obj)
+ {
+ if (obj is null)
+ return 1;
+
+ if (obj is PositiveAmount c)
+ return CompareTo(c);
+
+ throw new ArgumentException("Object is not a PositiveAmount", nameof(obj));
+ }
+
+ ///
+ public int CompareTo(PositiveAmount other)
+ {
+ if (!other._isInitialized)
+ return 1;
+ if (!_isInitialized)
+ return -1;
+ return _value.CompareTo(other._value);
+ }
+
+ ///
+ /// Implicit conversion from to
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static implicit operator PositiveAmount(int value) => new(value);
+
+ ///
+ /// Implicit conversion from (nullable) to (nullable)
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [return: NotNullIfNotNull(nameof(value))]
+ public static implicit operator PositiveAmount?(int? value) => value is null ? null : new(value.Value);
+
+ ///
+ /// Implicit conversion from to
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static implicit operator int(PositiveAmount value) => (int)value._valueOrThrow;
+
+ ///
+ /// Implicit conversion from (nullable) to (nullable)
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [return: NotNullIfNotNull(nameof(value))]
+ public static implicit operator int?(PositiveAmount? value) => value is null ? null : (int?)value.Value._valueOrThrow;
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static PositiveAmount operator +(PositiveAmount left, PositiveAmount right) => new(left._valueOrThrow + right._valueOrThrow);
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static PositiveAmount operator -(PositiveAmount left, PositiveAmount right) => new(left._valueOrThrow - right._valueOrThrow);
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static PositiveAmount operator *(PositiveAmount left, PositiveAmount right) => new(left._valueOrThrow * right._valueOrThrow);
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static PositiveAmount operator /(PositiveAmount left, PositiveAmount right) => new(left._valueOrThrow / right._valueOrThrow);
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static PositiveAmount operator %(PositiveAmount left, PositiveAmount right) => new(left._valueOrThrow % right._valueOrThrow);
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator <(PositiveAmount left, PositiveAmount right) => left._valueOrThrow < right._valueOrThrow;
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator <=(PositiveAmount left, PositiveAmount right) => left._valueOrThrow <= right._valueOrThrow;
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator >(PositiveAmount left, PositiveAmount right) => left._valueOrThrow > right._valueOrThrow;
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator >=(PositiveAmount left, PositiveAmount right) => left._valueOrThrow >= right._valueOrThrow;
+
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static PositiveAmount Parse(string s, IFormatProvider? provider) => int.Parse(s, provider);
+
+ ///
+ public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out PositiveAmount result)
+ {
+ if (!int.TryParse(s, provider, out var value))
+ {
+ result = default;
+ return false;
+ }
+
+ if (TryCreate(value, out var created))
+ {
+ result = created.Value;
+ return true;
+ }
+
+ result = default;
+ return false;
+ }
+
+#if NET8_0_OR_GREATER
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool TryFormat(Span utf8Destination, out int bytesWritten, ReadOnlySpan format, IFormatProvider? provider)
+ {
+ return ((IUtf8SpanFormattable)_valueOrThrow).TryFormat(utf8Destination, out bytesWritten, format, provider);
+ }
+#endif
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public override int GetHashCode() => _valueOrThrow.GetHashCode();
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ TypeCode IConvertible.GetTypeCode() => ((IConvertible)(Int32)_valueOrThrow).GetTypeCode();
+
+ ///
+ bool IConvertible.ToBoolean(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToBoolean(provider);
+
+ ///
+ byte IConvertible.ToByte(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToByte(provider);
+
+ ///
+ char IConvertible.ToChar(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToChar(provider);
+
+ ///
+ DateTime IConvertible.ToDateTime(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToDateTime(provider);
+
+ ///
+ decimal IConvertible.ToDecimal(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToDecimal(provider);
+
+ ///
+ double IConvertible.ToDouble(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToDouble(provider);
+
+ ///
+ short IConvertible.ToInt16(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToInt16(provider);
+
+ ///
+ int IConvertible.ToInt32(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToInt32(provider);
+
+ ///
+ long IConvertible.ToInt64(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToInt64(provider);
+
+ ///
+ sbyte IConvertible.ToSByte(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToSByte(provider);
+
+ ///
+ float IConvertible.ToSingle(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToSingle(provider);
+
+ ///
+ string IConvertible.ToString(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToString(provider);
+
+ ///
+ object IConvertible.ToType(Type conversionType, IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToType(conversionType, provider);
+
+ ///
+ ushort IConvertible.ToUInt16(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToUInt16(provider);
+
+ ///
+ uint IConvertible.ToUInt32(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToUInt32(provider);
+
+ ///
+ ulong IConvertible.ToUInt64(IFormatProvider? provider) => ((IConvertible)(Int32)_valueOrThrow).ToUInt64(provider);
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public override string ToString() => _valueOrThrow.ToString();
+}
diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#PositiveAmountJsonConverter.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#PositiveAmountJsonConverter.g.verified.cs
new file mode 100644
index 0000000..b835b44
--- /dev/null
+++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#PositiveAmountJsonConverter.g.verified.cs
@@ -0,0 +1,70 @@
+//HintName: PositiveAmountJsonConverter.g.cs
+//------------------------------------------------------------------------------
+//
+// This code was generated by 'AltaSoft DomainPrimitives Generator'.
+// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#nullable enable
+
+#pragma warning disable CS8774 // Member must have a non-null value when exiting.
+#pragma warning disable CS0628 // New protected member declared in sealed type
+#pragma warning disable CS0612 // Type or member is obsolete
+#pragma warning disable CS0618 // Type or member is obsolete
+#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor
+#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
+#pragma warning disable IDE0290 // Use primary constructor
+
+using AltaSoft.DomainPrimitives;
+using System;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Globalization;
+using System.Text.Json.Serialization.Metadata;
+
+namespace AltaSoft.DomainPrimitives.Converters;
+
+///
+/// JsonConverter for
+///
+internal sealed class PositiveAmountJsonConverter : JsonConverter
+{
+ ///
+ public override PositiveAmount Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ try
+ {
+ return JsonInternalConverters.Int32Converter.Read(ref reader, typeToConvert, options);
+ }
+ catch (InvalidDomainValueException ex)
+ {
+ throw new JsonException(ex.Message);
+ }
+ }
+
+ ///
+ public override void Write(Utf8JsonWriter writer, PositiveAmount value, JsonSerializerOptions options)
+ {
+ JsonInternalConverters.Int32Converter.Write(writer, (int)value, options);
+ }
+
+ ///
+ public override PositiveAmount ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ try
+ {
+ return JsonInternalConverters.Int32Converter.ReadAsPropertyName(ref reader, typeToConvert, options);
+ }
+ catch (InvalidDomainValueException ex)
+ {
+ throw new JsonException(ex.Message);
+ }
+ }
+
+ ///
+ public override void WriteAsPropertyName(Utf8JsonWriter writer, PositiveAmount value, JsonSerializerOptions options)
+ {
+ JsonInternalConverters.Int32Converter.WriteAsPropertyName(writer, (int)value, options);
+ }
+}
diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#PositiveAmountTypeConverter.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#PositiveAmountTypeConverter.g.verified.cs
new file mode 100644
index 0000000..1fa00a2
--- /dev/null
+++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithXmlExampleStringLengthAndPattern#PositiveAmountTypeConverter.g.verified.cs
@@ -0,0 +1,46 @@
+//HintName: PositiveAmountTypeConverter.g.cs
+//------------------------------------------------------------------------------
+//
+// This code was generated by 'AltaSoft DomainPrimitives Generator'.
+// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#nullable enable
+
+#pragma warning disable CS8774 // Member must have a non-null value when exiting.
+#pragma warning disable CS0628 // New protected member declared in sealed type
+#pragma warning disable CS0612 // Type or member is obsolete
+#pragma warning disable CS0618 // Type or member is obsolete
+#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor
+#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
+#pragma warning disable IDE0290 // Use primary constructor
+
+using AltaSoft.DomainPrimitives;
+using System;
+using System.ComponentModel;
+using System.Globalization;
+
+namespace AltaSoft.DomainPrimitives.Converters;
+
+///
+/// TypeConverter for
+///
+internal sealed class PositiveAmountTypeConverter : Int32Converter
+{
+ ///
+ public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
+ {
+ var result = base.ConvertFrom(context, culture, value);
+ if (result is null)
+ return null;
+ try
+ {
+ return new PositiveAmount((int)result);
+ }
+ catch (InvalidDomainValueException ex)
+ {
+ throw new FormatException("Cannot parse PositiveAmount", ex);
+ }
+ }
+}
diff --git a/tests/AltaSoft.DomainPrimitives.UnitTests/AltaSoft.DomainPrimitives.UnitTests.csproj b/tests/AltaSoft.DomainPrimitives.UnitTests/AltaSoft.DomainPrimitives.UnitTests.csproj
index 9bf9469..4019ba0 100644
--- a/tests/AltaSoft.DomainPrimitives.UnitTests/AltaSoft.DomainPrimitives.UnitTests.csproj
+++ b/tests/AltaSoft.DomainPrimitives.UnitTests/AltaSoft.DomainPrimitives.UnitTests.csproj
@@ -1,7 +1,7 @@
- net10.0
+ $(DefaultTargetFrameworks)
enable
enable
diff --git a/tests/AltaSoft.DomainPrimitives.XmlDataTypes.Tests/AltaSoft.DomainPrimitives.XmlDataTypes.Tests.csproj b/tests/AltaSoft.DomainPrimitives.XmlDataTypes.Tests/AltaSoft.DomainPrimitives.XmlDataTypes.Tests.csproj
index d999b85..3a9d607 100644
--- a/tests/AltaSoft.DomainPrimitives.XmlDataTypes.Tests/AltaSoft.DomainPrimitives.XmlDataTypes.Tests.csproj
+++ b/tests/AltaSoft.DomainPrimitives.XmlDataTypes.Tests/AltaSoft.DomainPrimitives.XmlDataTypes.Tests.csproj
@@ -1,7 +1,7 @@
- net10.0
+ $(DefaultTargetFrameworks)
enable
enable