From 817585889c4f522b2567187347e5d076ec2d304c Mon Sep 17 00:00:00 2001 From: Gregory Nikolaishvili Date: Mon, 15 Dec 2025 14:17:43 +0400 Subject: [PATCH 1/4] Refactor InvalidDomainValueException usage and messages Refactored how InvalidDomainValueException is constructed and thrown across the codebase for consistency and clarity. Introduced static factory methods for common error scenarios (not initialized, string range, limit exceeded) and improved error message formatting to always include the type and value. Updated all generated domain primitive types to use the new pattern. Also made minor documentation and whitespace corrections. --- .../Executor.cs | 7 +- .../Helpers/MethodGeneratorHelper.cs | 6 +- .../InvalidDomainValueException.cs | 76 +++++++++++++++++-- ...facesAndConverters#BoolValue.g.verified.cs | 6 +- ...facesAndConverters#ByteValue.g.verified.cs | 6 +- ...facesAndConverters#CharValue.g.verified.cs | 6 +- ...sAndConverters#DateOnlyValue.g.verified.cs | 6 +- ...tersWithXml#DateOnlyXmlValue.g.verified.cs | 6 +- ...nverters#DateTimeOffsetValue.g.verified.cs | 6 +- ...sAndConverters#DateTimeValue.g.verified.cs | 6 +- ...esAndConverters#DecimalValue.g.verified.cs | 6 +- ...er#WithoutJsonConverterValue.g.verified.cs | 6 +- ...er#WithoutTypeConverterValue.g.verified.cs | 6 +- ...cesAndConverters#DoubleValue.g.verified.cs | 6 +- ...acesAndConverters#FloatValue.g.verified.cs | 6 +- ...facesAndConverters#GuidValue.g.verified.cs | 6 +- ...acesAndConverters#ShortValue.g.verified.cs | 6 +- ...sAndConverters#IntOfIntValue.g.verified.cs | 6 +- ...rfacesAndConverters#IntValue.g.verified.cs | 6 +- ...rfacesAndConverters#IntValue.g.verified.cs | 6 +- ...facesAndConverters#LongValue.g.verified.cs | 6 +- ...acesAndConverters#SByteValue.g.verified.cs | 6 +- ...nverters#StringOfStringValue.g.verified.cs | 6 +- ...cesAndConverters#StringValue.g.verified.cs | 6 +- ...cesAndConverters#StringValue.g.verified.cs | 6 +- ...nalClass#InternalStringValue.g.verified.cs | 6 +- ...rmerCall#TransformableString.g.verified.cs | 6 +- ...sAndConverters#TimeOnlyValue.g.verified.cs | 6 +- ...sAndConverters#TimeSpanValue.g.verified.cs | 6 +- ...cesAndConverters#UShortValue.g.verified.cs | 6 +- ...rfacesAndConverters#IntValue.g.verified.cs | 6 +- ...facesAndConverters#LongValue.g.verified.cs | 6 +- .../ToXmlStringExtTests.cs | 0 33 files changed, 162 insertions(+), 101 deletions(-) create mode 100644 tests/AltaSoft.DomainPrimitives.UnitTests/ToXmlStringExtTests.cs diff --git a/src/AltaSoft.DomainPrimitives.Generator/Executor.cs b/src/AltaSoft.DomainPrimitives.Generator/Executor.cs index 09ad1f6..1a9bb62 100644 --- a/src/AltaSoft.DomainPrimitives.Generator/Executor.cs +++ b/src/AltaSoft.DomainPrimitives.Generator/Executor.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Globalization; using System.Linq; using System.Text; using System.Xml.Serialization; @@ -422,7 +423,7 @@ private static void Process(GeneratorData data, string ctorCode, DomainPrimitive { // Add int constructor builder.AppendComment("// Private constructor with 'int' value"); - builder.AppendLine($"private {data.ClassName}(int value) : this(value is >= {data.PrimitiveTypeFriendlyName}.MinValue and <= {data.PrimitiveTypeFriendlyName}.MaxValue ? ({data.PrimitiveTypeFriendlyName})value : throw new InvalidDomainValueException(\"The value has exceeded a {data.PrimitiveTypeFriendlyName} limit\"))") + builder.AppendLine($"private {data.ClassName}(int value) : this(value is >= {data.PrimitiveTypeFriendlyName}.MinValue and <= {data.PrimitiveTypeFriendlyName}.MaxValue ? ({data.PrimitiveTypeFriendlyName})value : throw InvalidDomainValueException.LimitExceededException(\"{data.PrimitiveTypeFriendlyName}\", typeof({data.ClassName}), value))") .OpenBracket() .CloseBracket() .NewLine(); @@ -718,7 +719,7 @@ private static bool ProcessConstructor(GeneratorData data, SourceCodeBuilder bui var underlyingTypeName = interfaceGenericType.GetFriendlyName(); - builder.AppendLine($"private {underlyingTypeName} _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException(\"The domain value has not been initialized\", this);"); + builder.AppendLine($"private {underlyingTypeName} _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof({type.Name}));"); builder.AppendLine("[DebuggerBrowsable(DebuggerBrowsableState.Never)]"); builder.AppendLine($"private readonly {underlyingTypeName} _value;"); @@ -796,7 +797,7 @@ private static void AddStringLengthAttributeValidation(ISymbol domainPrimitiveTy .AppendIf(hasMinValue, $"< {minValue}") .AppendIf(hasMinValue && hasMaxValue, " or ") .AppendIf(hasMaxValue, $"> {maxValue}").AppendLine(")") - .AppendLine($"\tthrow new InvalidDomainValueException(\"String length is out of range {minValue}..{maxValue}\", this);") + .AppendLine($"\tthrow InvalidDomainValueException.StringRangeException(value, {minValue.ToString(CultureInfo.InvariantCulture)}, {maxValue.ToString(CultureInfo.InvariantCulture)});") .NewLine(); } } diff --git a/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs b/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs index a6256d0..9502f48 100644 --- a/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs +++ b/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs @@ -432,7 +432,7 @@ internal static void GenerateMandatoryMethods(GeneratorData data, SourceCodeBuil .CloseBracket() .NewLine(); - builder.AppendSummary(" Validates the specified value and throws an exception if it is not valid.") + builder.AppendSummary("Validates the specified value and throws an exception if it is not valid.") .AppendParamDescription("value", "The value to validate") .AppendExceptionDescription("InvalidDomainValueException", "Thrown when the value is not valid."); @@ -440,7 +440,7 @@ internal static void GenerateMandatoryMethods(GeneratorData data, SourceCodeBuil .OpenBracket() .AppendLine("var result = Validate(value);") .AppendLine("if (!result.IsValid)") - .AppendLine("\tthrow new InvalidDomainValueException(result.ErrorMessage, this);") + .AppendLine($"\tthrow new InvalidDomainValueException(result.ErrorMessage, typeof({data.ClassName}), value);") .CloseBracket() .NewLine(); @@ -464,7 +464,7 @@ static void AddStringLengthValidation(GeneratorData data, SourceCodeBuilder sb) .AppendIf(hasMaxValue, $"> {maxValue}").AppendLine(")") .OpenBracket() .AppendLine("result = null;") - .AppendLine($"errorMessage =\" String length is out of range {minValue}..{maxValue}\";") + .AppendLine($"errorMessage = \"String length is out of range {minValue}..{maxValue}\";") .AppendLine("return false;") .CloseBracket() .NewLine(); diff --git a/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs b/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs index 4d4dd6a..08cbbad 100644 --- a/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs +++ b/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs @@ -13,22 +13,82 @@ public class InvalidDomainValueException : Exception /// Initializes a new instance of the class with a specific error message. /// /// The error message that describes the reason for the exception. - /// actual instance of domain primitive + /// The of the domain primitive that failed validation. + /// The underlying value that caused the failure, or null if not applicable. [EditorBrowsable(EditorBrowsableState.Never)] - public InvalidDomainValueException(string message, IDomainValue instance) : base(GenerateErrorMessage(message, instance)) + public InvalidDomainValueException(string message, Type type, object? value) : base(GenerateErrorMessage(message, type, value)) { } /// - /// Generates the error message for the . + /// Initializes a new instance of the class with a specific error message. /// /// The error message that describes the reason for the exception. - /// The actual value of the domain primitive. - /// The generated error message. - private static string GenerateErrorMessage(string message, IDomainValue value) + /// The of the domain primitive that failed validation. + [EditorBrowsable(EditorBrowsableState.Never)] + public InvalidDomainValueException(string message, Type type) : base(GenerateErrorMessage(message, type)) + { + } + + /// + /// Creates an that indicates the domain value has not been initialized. + /// + /// The of the domain primitive that is not initialized. + /// An describing the not-initialized error. + [EditorBrowsable(EditorBrowsableState.Never)] + public static InvalidDomainValueException NotInitializedException(Type type) + { + return new InvalidDomainValueException("The domain value has not been initialized", type); + } + + /// + /// Creates an for string length range violations. + /// + /// The string value that caused the violation. + /// The minimum allowed length. + /// The maximum allowed length. + /// An describing the range violation. + [EditorBrowsable(EditorBrowsableState.Never)] + public static InvalidDomainValueException StringRangeException(string value, int min, int max) + { + return new InvalidDomainValueException($"String length is out of range {min}..{max}", typeof(string), value); + } + + /// + /// Creates an for numeric limit exceeded errors. + /// + /// The of the domain primitive. + /// The numeric value that exceeded the limit. + /// The name of the underlying primitive type. + /// An describing the limit exceeded error. + [EditorBrowsable(EditorBrowsableState.Never)] + public static InvalidDomainValueException LimitExceededException(Type type, int value, string underlyingTypeName) + { + return new InvalidDomainValueException($"The value has exceeded a {underlyingTypeName} limit", type, value); + } + + /// + /// Generates the error message for the including the underlying value. + /// + /// The main error message. + /// The of the domain primitive. + /// The underlying value that caused the error, or null. + /// A formatted error message string. + private static string GenerateErrorMessage(string message, Type type, object? value) + { + var typeName = type.FullName ?? type.Name; + return $"Cannot create instance of '{typeName}'. {message}. Value: {value ?? "null"}"; + } + + /// + /// Generates the error message for the without the underlying value. + /// + /// The main error message. + /// The of the domain primitive. + /// A formatted error message string. + private static string GenerateErrorMessage(string message, Type type) { - var type = value.GetType(); var typeName = type.FullName ?? type.Name; - return $"Cannot create instance of '{typeName}'. {message}"; + return $"Cannot create instance of '{typeName}'. {message}."; } } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.BoolValue_GeneratesAllInterfacesAndConverters#BoolValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.BoolValue_GeneratesAllInterfacesAndConverters#BoolValue.g.verified.cs index 4d05260..46a52fe 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.BoolValue_GeneratesAllInterfacesAndConverters#BoolValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.BoolValue_GeneratesAllInterfacesAndConverters#BoolValue.g.verified.cs @@ -35,7 +35,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (bool)this; - private bool _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private bool _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(BoolValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly bool _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -99,7 +99,7 @@ public static bool TryCreate(bool value, [NotNullWhen(true)] out BoolValue? res } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -107,7 +107,7 @@ public void ValidateOrThrow(bool value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(BoolValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.ByteValue_GeneratesAllInterfacesAndConverters#ByteValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.ByteValue_GeneratesAllInterfacesAndConverters#ByteValue.g.verified.cs index 812598c..6328cfe 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.ByteValue_GeneratesAllInterfacesAndConverters#ByteValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.ByteValue_GeneratesAllInterfacesAndConverters#ByteValue.g.verified.cs @@ -39,7 +39,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (byte)this; - private byte _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private byte _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(ByteValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly byte _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -103,7 +103,7 @@ public static bool TryCreate(byte value, [NotNullWhen(true)] out ByteValue? res } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -111,7 +111,7 @@ public void ValidateOrThrow(byte value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(ByteValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.CharValue_GeneratesAllInterfacesAndConverters#CharValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.CharValue_GeneratesAllInterfacesAndConverters#CharValue.g.verified.cs index 0b35375..ea71ade 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.CharValue_GeneratesAllInterfacesAndConverters#CharValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.CharValue_GeneratesAllInterfacesAndConverters#CharValue.g.verified.cs @@ -39,7 +39,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (char)this; - private char _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private char _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(CharValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly char _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -103,7 +103,7 @@ public static bool TryCreate(char value, [NotNullWhen(true)] out CharValue? res } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -111,7 +111,7 @@ public void ValidateOrThrow(char value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(CharValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateOnlyValue_GeneratesAllInterfacesAndConverters#DateOnlyValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateOnlyValue_GeneratesAllInterfacesAndConverters#DateOnlyValue.g.verified.cs index 4920ca6..45cdab2 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateOnlyValue_GeneratesAllInterfacesAndConverters#DateOnlyValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateOnlyValue_GeneratesAllInterfacesAndConverters#DateOnlyValue.g.verified.cs @@ -40,7 +40,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (DateOnly)this; - private DateOnly _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private DateOnly _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(DateOnlyValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly DateOnly _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -104,7 +104,7 @@ public static bool TryCreate(DateOnly value, [NotNullWhen(true)] out DateOnlyVa } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -112,7 +112,7 @@ public void ValidateOrThrow(DateOnly value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(DateOnlyValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateOnlyValue_GeneratesAllInterfacesAndConvertersWithXml#DateOnlyXmlValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateOnlyValue_GeneratesAllInterfacesAndConvertersWithXml#DateOnlyXmlValue.g.verified.cs index f1697c7..e0cb7aa 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateOnlyValue_GeneratesAllInterfacesAndConvertersWithXml#DateOnlyXmlValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateOnlyValue_GeneratesAllInterfacesAndConvertersWithXml#DateOnlyXmlValue.g.verified.cs @@ -39,7 +39,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (DateOnly)this; - private DateOnly _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private DateOnly _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(DateOnlyXmlValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly DateOnly _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -103,7 +103,7 @@ public static bool TryCreate(DateOnly value, [NotNullWhen(true)] out DateOnlyXm } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -111,7 +111,7 @@ public void ValidateOrThrow(DateOnly value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(DateOnlyXmlValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateTimeOffsetValue_GeneratesAllInterfacesAndConverters#DateTimeOffsetValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateTimeOffsetValue_GeneratesAllInterfacesAndConverters#DateTimeOffsetValue.g.verified.cs index 0e12677..2830ffe 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateTimeOffsetValue_GeneratesAllInterfacesAndConverters#DateTimeOffsetValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateTimeOffsetValue_GeneratesAllInterfacesAndConverters#DateTimeOffsetValue.g.verified.cs @@ -39,7 +39,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (DateTimeOffset)this; - private DateTimeOffset _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private DateTimeOffset _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(DateTimeOffsetValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly DateTimeOffset _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -103,7 +103,7 @@ public static bool TryCreate(DateTimeOffset value, [NotNullWhen(true)] out Date } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -111,7 +111,7 @@ public void ValidateOrThrow(DateTimeOffset value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(DateTimeOffsetValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateTimeValue_GeneratesAllInterfacesAndConverters#DateTimeValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateTimeValue_GeneratesAllInterfacesAndConverters#DateTimeValue.g.verified.cs index ce580c0..5007a1d 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateTimeValue_GeneratesAllInterfacesAndConverters#DateTimeValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DateTimeValue_GeneratesAllInterfacesAndConverters#DateTimeValue.g.verified.cs @@ -40,7 +40,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (DateTime)this; - private DateTime _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private DateTime _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(DateTimeValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly DateTime _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -104,7 +104,7 @@ public static bool TryCreate(DateTime value, [NotNullWhen(true)] out DateTimeVa } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -112,7 +112,7 @@ public void ValidateOrThrow(DateTime value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(DateTimeValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DecimalValue_GeneratesAllInterfacesAndConverters#DecimalValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DecimalValue_GeneratesAllInterfacesAndConverters#DecimalValue.g.verified.cs index 7903472..8c7f115 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DecimalValue_GeneratesAllInterfacesAndConverters#DecimalValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DecimalValue_GeneratesAllInterfacesAndConverters#DecimalValue.g.verified.cs @@ -44,7 +44,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (decimal)this; - private decimal _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private decimal _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(DecimalValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly decimal _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -108,7 +108,7 @@ public static bool TryCreate(decimal value, [NotNullWhen(true)] out DecimalValu } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -116,7 +116,7 @@ public void ValidateOrThrow(decimal value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(DecimalValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DomainPrimitiveWithoutJsonConverters_ShouldNotAddJsonConverter#WithoutJsonConverterValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DomainPrimitiveWithoutJsonConverters_ShouldNotAddJsonConverter#WithoutJsonConverterValue.g.verified.cs index 89e8013..e5c46a7 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DomainPrimitiveWithoutJsonConverters_ShouldNotAddJsonConverter#WithoutJsonConverterValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DomainPrimitiveWithoutJsonConverters_ShouldNotAddJsonConverter#WithoutJsonConverterValue.g.verified.cs @@ -42,7 +42,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (uint)this; - private uint _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private uint _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(WithoutJsonConverterValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly uint _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -106,7 +106,7 @@ public static bool TryCreate(uint value, [NotNullWhen(true)] out WithoutJsonCon } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -114,7 +114,7 @@ public void ValidateOrThrow(uint value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(WithoutJsonConverterValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DomainPrimitiveWithoutTypeConverters_ShouldNotAddJsonConverter#WithoutTypeConverterValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DomainPrimitiveWithoutTypeConverters_ShouldNotAddJsonConverter#WithoutTypeConverterValue.g.verified.cs index 5e7f00e..8ddfca0 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DomainPrimitiveWithoutTypeConverters_ShouldNotAddJsonConverter#WithoutTypeConverterValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DomainPrimitiveWithoutTypeConverters_ShouldNotAddJsonConverter#WithoutTypeConverterValue.g.verified.cs @@ -42,7 +42,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (uint)this; - private uint _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private uint _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(WithoutTypeConverterValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly uint _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -106,7 +106,7 @@ public static bool TryCreate(uint value, [NotNullWhen(true)] out WithoutTypeCon } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -114,7 +114,7 @@ public void ValidateOrThrow(uint value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(WithoutTypeConverterValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DoubleValue_GeneratesAllInterfacesAndConverters#DoubleValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DoubleValue_GeneratesAllInterfacesAndConverters#DoubleValue.g.verified.cs index b8e4a0d..99eb572 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DoubleValue_GeneratesAllInterfacesAndConverters#DoubleValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.DoubleValue_GeneratesAllInterfacesAndConverters#DoubleValue.g.verified.cs @@ -44,7 +44,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (double)this; - private double _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private double _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(DoubleValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly double _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -108,7 +108,7 @@ public static bool TryCreate(double value, [NotNullWhen(true)] out DoubleValue? } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -116,7 +116,7 @@ public void ValidateOrThrow(double value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(DoubleValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.FloatValue_GeneratesAllInterfacesAndConverters#FloatValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.FloatValue_GeneratesAllInterfacesAndConverters#FloatValue.g.verified.cs index cd5300c..12c06ef 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.FloatValue_GeneratesAllInterfacesAndConverters#FloatValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.FloatValue_GeneratesAllInterfacesAndConverters#FloatValue.g.verified.cs @@ -44,7 +44,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (float)this; - private float _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private float _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(FloatValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly float _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -108,7 +108,7 @@ public static bool TryCreate(float value, [NotNullWhen(true)] out FloatValue? r } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -116,7 +116,7 @@ public void ValidateOrThrow(float value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(FloatValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.GuidValue_GeneratesAllInterfacesAndConverters#GuidValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.GuidValue_GeneratesAllInterfacesAndConverters#GuidValue.g.verified.cs index 1d38a9b..6534e9f 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.GuidValue_GeneratesAllInterfacesAndConverters#GuidValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.GuidValue_GeneratesAllInterfacesAndConverters#GuidValue.g.verified.cs @@ -38,7 +38,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (Guid)this; - private Guid _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private Guid _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(GuidValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly Guid _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -102,7 +102,7 @@ public static bool TryCreate(Guid value, [NotNullWhen(true)] out GuidValue? res } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -110,7 +110,7 @@ public void ValidateOrThrow(Guid value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(GuidValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.Int16Value_GeneratesAllInterfacesAndConverters#ShortValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.Int16Value_GeneratesAllInterfacesAndConverters#ShortValue.g.verified.cs index 31fc2f9..9f397b2 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.Int16Value_GeneratesAllInterfacesAndConverters#ShortValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.Int16Value_GeneratesAllInterfacesAndConverters#ShortValue.g.verified.cs @@ -39,7 +39,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (short)this; - private short _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private short _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(ShortValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly short _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -103,7 +103,7 @@ public static bool TryCreate(short value, [NotNullWhen(true)] out ShortValue? r } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -111,7 +111,7 @@ public void ValidateOrThrow(short value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(ShortValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntOfIntValue_GeneratesAllInterfacesAndConverters#IntOfIntValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntOfIntValue_GeneratesAllInterfacesAndConverters#IntOfIntValue.g.verified.cs index 473a84e..c897a09 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntOfIntValue_GeneratesAllInterfacesAndConverters#IntOfIntValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntOfIntValue_GeneratesAllInterfacesAndConverters#IntOfIntValue.g.verified.cs @@ -41,7 +41,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (int)this; - private IntValue _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private IntValue _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(IntOfIntValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly IntValue _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -105,7 +105,7 @@ public static bool TryCreate(IntValue value, [NotNullWhen(true)] out IntOfIntVa } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -113,7 +113,7 @@ public void ValidateOrThrow(IntValue value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(IntOfIntValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntOfIntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntOfIntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs index b3aa937..f30eadf 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntOfIntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntOfIntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs @@ -44,7 +44,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (int)this; - private int _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private int _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(IntValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly int _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -108,7 +108,7 @@ public static bool TryCreate(int value, [NotNullWhen(true)] out IntValue? resul } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -116,7 +116,7 @@ public void ValidateOrThrow(int value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(IntValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs index b3aa937..f30eadf 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.IntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs @@ -44,7 +44,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (int)this; - private int _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private int _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(IntValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly int _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -108,7 +108,7 @@ public static bool TryCreate(int value, [NotNullWhen(true)] out IntValue? resul } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -116,7 +116,7 @@ public void ValidateOrThrow(int value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(IntValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.LongValue_GeneratesAllInterfacesAndConverters#LongValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.LongValue_GeneratesAllInterfacesAndConverters#LongValue.g.verified.cs index 1daaa19..b29652f 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.LongValue_GeneratesAllInterfacesAndConverters#LongValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.LongValue_GeneratesAllInterfacesAndConverters#LongValue.g.verified.cs @@ -44,7 +44,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (long)this; - private long _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private long _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(LongValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly long _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -108,7 +108,7 @@ public static bool TryCreate(long value, [NotNullWhen(true)] out LongValue? res } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -116,7 +116,7 @@ public void ValidateOrThrow(long value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(LongValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.SByteValue_GeneratesAllInterfacesAndConverters#SByteValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.SByteValue_GeneratesAllInterfacesAndConverters#SByteValue.g.verified.cs index 939d76a..4cf122d 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.SByteValue_GeneratesAllInterfacesAndConverters#SByteValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.SByteValue_GeneratesAllInterfacesAndConverters#SByteValue.g.verified.cs @@ -39,7 +39,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (sbyte)this; - private sbyte _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private sbyte _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(SByteValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly sbyte _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -103,7 +103,7 @@ public static bool TryCreate(sbyte value, [NotNullWhen(true)] out SByteValue? r } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -111,7 +111,7 @@ public void ValidateOrThrow(sbyte value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(SByteValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringOfStringValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringOfStringValue.g.verified.cs index 5befaca..11f3f9b 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringOfStringValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringOfStringValue.g.verified.cs @@ -35,7 +35,7 @@ public partial class StringOfStringValue : IEquatable /// public object GetUnderlyingPrimitiveValue() => (string)this; - private StringValue _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private StringValue _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(StringOfStringValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly StringValue _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -101,7 +101,7 @@ public static bool TryCreate(StringValue value, [NotNullWhen(true)] out StringO } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -109,7 +109,7 @@ public void ValidateOrThrow(StringValue value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(StringOfStringValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs index 28d280f..78a0834 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs @@ -35,7 +35,7 @@ public partial class StringValue : IEquatable /// public object GetUnderlyingPrimitiveValue() => (string)this; - private string _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private string _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(StringValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly string _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -101,7 +101,7 @@ public static bool TryCreate(string value, [NotNullWhen(true)] out StringValue? } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -109,7 +109,7 @@ public void ValidateOrThrow(string value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(StringValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs index 28d280f..78a0834 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs @@ -35,7 +35,7 @@ public partial class StringValue : IEquatable /// public object GetUnderlyingPrimitiveValue() => (string)this; - private string _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private string _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(StringValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly string _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -101,7 +101,7 @@ public static bool TryCreate(string value, [NotNullWhen(true)] out StringValue? } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -109,7 +109,7 @@ public void ValidateOrThrow(string value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(StringValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConvertersForInternalClass#InternalStringValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConvertersForInternalClass#InternalStringValue.g.verified.cs index e881ef2..967ba85 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConvertersForInternalClass#InternalStringValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConvertersForInternalClass#InternalStringValue.g.verified.cs @@ -35,7 +35,7 @@ internal partial class InternalStringValue : IEquatable /// public object GetUnderlyingPrimitiveValue() => (string)this; - private string _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private string _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(InternalStringValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly string _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -101,7 +101,7 @@ public static bool TryCreate(string value, [NotNullWhen(true)] out InternalStri } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -109,7 +109,7 @@ public void ValidateOrThrow(string value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(InternalStringValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransformerGeneratesTransformerCall#TransformableString.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransformerGeneratesTransformerCall#TransformableString.g.verified.cs index 63f4f09..7a325d2 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransformerGeneratesTransformerCall#TransformableString.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransformerGeneratesTransformerCall#TransformableString.g.verified.cs @@ -35,7 +35,7 @@ internal partial class TransformableString : IEquatable /// public object GetUnderlyingPrimitiveValue() => (string)this; - private string _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private string _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(TransformableString)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly string _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -102,7 +102,7 @@ public static bool TryCreate(string value, [NotNullWhen(true)] out Transformabl } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -110,7 +110,7 @@ public void ValidateOrThrow(string value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(TransformableString), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.TimeOnlyValue_GeneratesAllInterfacesAndConverters#TimeOnlyValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.TimeOnlyValue_GeneratesAllInterfacesAndConverters#TimeOnlyValue.g.verified.cs index d14b1c6..8d93697 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.TimeOnlyValue_GeneratesAllInterfacesAndConverters#TimeOnlyValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.TimeOnlyValue_GeneratesAllInterfacesAndConverters#TimeOnlyValue.g.verified.cs @@ -40,7 +40,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (TimeOnly)this; - private TimeOnly _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private TimeOnly _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(TimeOnlyValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly TimeOnly _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -104,7 +104,7 @@ public static bool TryCreate(TimeOnly value, [NotNullWhen(true)] out TimeOnlyVa } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -112,7 +112,7 @@ public void ValidateOrThrow(TimeOnly value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(TimeOnlyValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.TimeSpanValue_GeneratesAllInterfacesAndConverters#TimeSpanValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.TimeSpanValue_GeneratesAllInterfacesAndConverters#TimeSpanValue.g.verified.cs index d63785c..3bf8d48 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.TimeSpanValue_GeneratesAllInterfacesAndConverters#TimeSpanValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.TimeSpanValue_GeneratesAllInterfacesAndConverters#TimeSpanValue.g.verified.cs @@ -39,7 +39,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (TimeSpan)this; - private TimeSpan _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private TimeSpan _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(TimeSpanValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly TimeSpan _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -103,7 +103,7 @@ public static bool TryCreate(TimeSpan value, [NotNullWhen(true)] out TimeSpanVa } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -111,7 +111,7 @@ public void ValidateOrThrow(TimeSpan value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(TimeSpanValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.UInt16Value_GeneratesAllInterfacesAndConverters#UShortValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.UInt16Value_GeneratesAllInterfacesAndConverters#UShortValue.g.verified.cs index 74ee36d..1b343ec 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.UInt16Value_GeneratesAllInterfacesAndConverters#UShortValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.UInt16Value_GeneratesAllInterfacesAndConverters#UShortValue.g.verified.cs @@ -39,7 +39,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (ushort)this; - private ushort _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private ushort _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(UShortValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ushort _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -103,7 +103,7 @@ public static bool TryCreate(ushort value, [NotNullWhen(true)] out UShortValue? } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -111,7 +111,7 @@ public void ValidateOrThrow(ushort value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(UShortValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.UIntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.UIntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs index 02a5964..ff8c73c 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.UIntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.UIntValue_GeneratesAllInterfacesAndConverters#IntValue.g.verified.cs @@ -44,7 +44,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (uint)this; - private uint _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private uint _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(IntValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly uint _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -108,7 +108,7 @@ public static bool TryCreate(uint value, [NotNullWhen(true)] out IntValue? resu } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -116,7 +116,7 @@ public void ValidateOrThrow(uint value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(IntValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.ULongValue_GeneratesAllInterfacesAndConverters#LongValue.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.ULongValue_GeneratesAllInterfacesAndConverters#LongValue.g.verified.cs index 991023b..fd89673 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.ULongValue_GeneratesAllInterfacesAndConverters#LongValue.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.ULongValue_GeneratesAllInterfacesAndConverters#LongValue.g.verified.cs @@ -44,7 +44,7 @@ namespace AltaSoft.DomainPrimitives; /// public object GetUnderlyingPrimitiveValue() => (ulong)this; - private ulong _valueOrThrow => _isInitialized ? _value : throw new InvalidDomainValueException("The domain value has not been initialized", this); + private ulong _valueOrThrow => _isInitialized ? _value : throw InvalidDomainValueException.NotInitializedException(typeof(LongValue)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ulong _value; [DebuggerBrowsable(DebuggerBrowsableState.Never)] @@ -108,7 +108,7 @@ public static bool TryCreate(ulong value, [NotNullWhen(true)] out LongValue? re } /// - /// Validates the specified value and throws an exception if it is not valid. + /// Validates the specified value and throws an exception if it is not valid. /// /// The value to validate /// Thrown when the value is not valid. @@ -116,7 +116,7 @@ public void ValidateOrThrow(ulong value) { var result = Validate(value); if (!result.IsValid) - throw new InvalidDomainValueException(result.ErrorMessage, this); + throw new InvalidDomainValueException(result.ErrorMessage, typeof(LongValue), value); } diff --git a/tests/AltaSoft.DomainPrimitives.UnitTests/ToXmlStringExtTests.cs b/tests/AltaSoft.DomainPrimitives.UnitTests/ToXmlStringExtTests.cs new file mode 100644 index 0000000..e69de29 From 3b9d2ce82777a5596407993c912affd93b9ae0ed Mon Sep 17 00:00:00 2001 From: Gregory Nikolaishvili Date: Mon, 15 Dec 2025 14:41:54 +0400 Subject: [PATCH 2/4] Update src/AltaSoft.DomainPrimitives.Generator/Executor.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/AltaSoft.DomainPrimitives.Generator/Executor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AltaSoft.DomainPrimitives.Generator/Executor.cs b/src/AltaSoft.DomainPrimitives.Generator/Executor.cs index 1a9bb62..2ac9255 100644 --- a/src/AltaSoft.DomainPrimitives.Generator/Executor.cs +++ b/src/AltaSoft.DomainPrimitives.Generator/Executor.cs @@ -423,7 +423,7 @@ private static void Process(GeneratorData data, string ctorCode, DomainPrimitive { // Add int constructor builder.AppendComment("// Private constructor with 'int' value"); - builder.AppendLine($"private {data.ClassName}(int value) : this(value is >= {data.PrimitiveTypeFriendlyName}.MinValue and <= {data.PrimitiveTypeFriendlyName}.MaxValue ? ({data.PrimitiveTypeFriendlyName})value : throw InvalidDomainValueException.LimitExceededException(\"{data.PrimitiveTypeFriendlyName}\", typeof({data.ClassName}), value))") + builder.AppendLine($"private {data.ClassName}(int value) : this(value is >= {data.PrimitiveTypeFriendlyName}.MinValue and <= {data.PrimitiveTypeFriendlyName}.MaxValue ? ({data.PrimitiveTypeFriendlyName})value : throw InvalidDomainValueException.LimitExceededException(typeof({data.ClassName}), value, \"{data.PrimitiveTypeFriendlyName}\"))") .OpenBracket() .CloseBracket() .NewLine(); From f3370bdbe594eede180341f41067b313ad346709 Mon Sep 17 00:00:00 2001 From: Gregory Nikolaishvili Date: Mon, 15 Dec 2025 14:42:33 +0400 Subject: [PATCH 3/4] Update src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs b/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs index 08cbbad..2e12278 100644 --- a/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs +++ b/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs @@ -44,14 +44,15 @@ public static InvalidDomainValueException NotInitializedException(Type type) /// /// Creates an for string length range violations. /// + /// The of the domain primitive. /// The string value that caused the violation. /// The minimum allowed length. /// The maximum allowed length. /// An describing the range violation. [EditorBrowsable(EditorBrowsableState.Never)] - public static InvalidDomainValueException StringRangeException(string value, int min, int max) + public static InvalidDomainValueException StringRangeException(Type type, string value, int min, int max) { - return new InvalidDomainValueException($"String length is out of range {min}..{max}", typeof(string), value); + return new InvalidDomainValueException($"String length is out of range {min}..{max}", type, value); } /// From 1cd89a10646cc335936982a819286f7f3b5d02c2 Mon Sep 17 00:00:00 2001 From: Gregory Nikolaishvili Date: Mon, 15 Dec 2025 14:50:39 +0400 Subject: [PATCH 4/4] Improve string length validation and error messages - Include domain primitive type in string length exception messages. - Quote string values and display (null) for nulls in error output. - Add explicit string length checks in constructors and TryCreate. - Introduce NestedString test class with [StringLength] attribute. - Ensure more robust and consistent enforcement of string constraints. --- src/AltaSoft.DomainPrimitives.Generator/Executor.cs | 2 +- .../InvalidDomainValueException.cs | 8 +++++++- .../DomainPrimitiveGeneratorTest.cs | 1 + ...esTransformerCall#TransformableString.g.verified.cs | 10 ++++++++++ .../TransformableTests/NestedString.cs | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/AltaSoft.DomainPrimitives.Generator/Executor.cs b/src/AltaSoft.DomainPrimitives.Generator/Executor.cs index 2ac9255..07c0217 100644 --- a/src/AltaSoft.DomainPrimitives.Generator/Executor.cs +++ b/src/AltaSoft.DomainPrimitives.Generator/Executor.cs @@ -797,7 +797,7 @@ private static void AddStringLengthAttributeValidation(ISymbol domainPrimitiveTy .AppendIf(hasMinValue, $"< {minValue}") .AppendIf(hasMinValue && hasMaxValue, " or ") .AppendIf(hasMaxValue, $"> {maxValue}").AppendLine(")") - .AppendLine($"\tthrow InvalidDomainValueException.StringRangeException(value, {minValue.ToString(CultureInfo.InvariantCulture)}, {maxValue.ToString(CultureInfo.InvariantCulture)});") + .AppendLine($"\tthrow InvalidDomainValueException.StringRangeException(typeof({data.ClassName}), value, {minValue.ToString(CultureInfo.InvariantCulture)}, {maxValue.ToString(CultureInfo.InvariantCulture)});") .NewLine(); } } diff --git a/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs b/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs index 2e12278..e8238da 100644 --- a/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs +++ b/src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs @@ -78,7 +78,13 @@ public static InvalidDomainValueException LimitExceededException(Type type, int private static string GenerateErrorMessage(string message, Type type, object? value) { var typeName = type.FullName ?? type.Name; - return $"Cannot create instance of '{typeName}'. {message}. Value: {value ?? "null"}"; + var strValue = value switch + { + null => "(null)", + string s => $"\"{s}\"", + _ => value.ToString() + }; + return $"Cannot create instance of '{typeName}'. {message}. Value: {strValue}"; } /// diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/DomainPrimitiveGeneratorTest.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/DomainPrimitiveGeneratorTest.cs index 6e0e4dd..21b34ee 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/DomainPrimitiveGeneratorTest.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/DomainPrimitiveGeneratorTest.cs @@ -25,6 +25,7 @@ public Task StringValue_WithTransformerGeneratesTransformerCall() namespace AltaSoft.DomainPrimitives; /// + [StringLength(1, 100)] internal partial class TransformableString : IDomainValue { /// diff --git a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransformerGeneratesTransformerCall#TransformableString.g.verified.cs b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransformerGeneratesTransformerCall#TransformableString.g.verified.cs index 7a325d2..24e3294 100644 --- a/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransformerGeneratesTransformerCall#TransformableString.g.verified.cs +++ b/tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransformerGeneratesTransformerCall#TransformableString.g.verified.cs @@ -53,6 +53,9 @@ private TransformableString(string value, bool validate) { if (validate) { + if (value.Length is < 1 or > 100) + throw InvalidDomainValueException.StringRangeException(typeof(TransformableString), value, 1, 100); + ValidateOrThrow(value); } _value = value; @@ -88,6 +91,13 @@ public static bool TryCreate(string value, [NotNullWhen(true)] out Transformable public static bool TryCreate(string value, [NotNullWhen(true)] out TransformableString? result, [NotNullWhen(false)] out string? errorMessage) { value = Transform(value); + if (value.Length is < 1 or > 100) + { + result = null; + errorMessage = "String length is out of range 1..100"; + return false; + } + var validationResult = Validate(value); if (!validationResult.IsValid) { diff --git a/tests/AltaSoft.DomainPrimitives.UnitTests/TransformableTests/NestedString.cs b/tests/AltaSoft.DomainPrimitives.UnitTests/TransformableTests/NestedString.cs index 1497755..53f608a 100644 --- a/tests/AltaSoft.DomainPrimitives.UnitTests/TransformableTests/NestedString.cs +++ b/tests/AltaSoft.DomainPrimitives.UnitTests/TransformableTests/NestedString.cs @@ -1,5 +1,6 @@ namespace AltaSoft.DomainPrimitives.UnitTests.TransformableTests; +[StringLength(2, 50)] public sealed partial class NestedString : IDomainValue { public static PrimitiveValidationResult Validate(ToUpperString value)