Closed aradalvand closed 3 days ago
It overrides Object.ToString(), which returns a nullable string.
https://learn.microsoft.com/en-us/dotnet/api/system.object.tostring?view=net-8.0
There was a huge thread on the CLR repo about this. I'll see if I can find the link.
@aradalvand can you share your exact definition? I guess it's a record struct or struct? Is it readonly?
@SteveDunn Sure:
[ValueObject<decimal>]
public readonly partial struct Rial;
Actually, there were some minor tweeks in the latest versions of Vogen around this. Quite a lot of the ToString
code was changed to facilitate IFormattable
hoisting. I can see in the latest RC versions, that structs that wraps a decimal, it generates this:
/// <inheritdoc cref = "System.Decimal.ToString()"/>
public override global::System.String ToString() => IsInitialized() ? Value.ToString() ?? "" : "[UNINITIALIZED]";
So, even though Object.ToString
and ValueType.ToString
return string?
, Vogen doesn't because it checks for null and returns an empty string.
Please let me know if the RC versions better match what you expect.
Closing this for now, but if you feel it needs further investigation, please shout. Thanks for the feedback!
Describe the bug
Vogen generates this:
Steps to reproduce
Create any value object.
Expected behaviour
The
ToString()
object never returnsnull
, its return type should not be nullable.