From e3f8790d79d98c4e194dd15cf6e1942db6141b4c Mon Sep 17 00:00:00 2001 From: Steve Dunn Date: Sun, 28 Apr 2024 13:07:56 +0100 Subject: [PATCH] Fix and tests --- src/Vogen/SemanticHelper.cs | 3 +- tests/ConsumerTests/BugFixTests/Tests.cs | 20 + ...575_AttributesWithArraysBreaksGenerator.cs | 48 ++ ...ithArraysBreaksGenerator.Test.verified.txt | 427 +++++++++++++ ...ithArraysBreaksGenerator.Test.verified.txt | 371 ++++++++++++ ...ithArraysBreaksGenerator.Test.verified.txt | 371 ++++++++++++ ...ithArraysBreaksGenerator.Test.verified.txt | 427 +++++++++++++ ...ithArraysBreaksGenerator.Test.verified.txt | 427 +++++++++++++ ...ithArraysBreaksGenerator.Test.verified.txt | 483 +++++++++++++++ ...ithArraysBreaksGenerator.Test.verified.txt | 573 ++++++++++++++++++ 10 files changed, 3149 insertions(+), 1 deletion(-) create mode 100644 tests/ConsumerTests/BugFixTests/Tests.cs create mode 100644 tests/SnapshotTests/BugFixes/Bug575_AttributesWithArraysBreaksGenerator.cs create mode 100644 tests/SnapshotTests/BugFixes/snapshots/snap-v3.1/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt create mode 100644 tests/SnapshotTests/BugFixes/snapshots/snap-v4.6.1/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt create mode 100644 tests/SnapshotTests/BugFixes/snapshots/snap-v4.8/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt create mode 100644 tests/SnapshotTests/BugFixes/snapshots/snap-v5.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt create mode 100644 tests/SnapshotTests/BugFixes/snapshots/snap-v6.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt create mode 100644 tests/SnapshotTests/BugFixes/snapshots/snap-v7.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt create mode 100644 tests/SnapshotTests/BugFixes/snapshots/snap-v8.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt diff --git a/src/Vogen/SemanticHelper.cs b/src/Vogen/SemanticHelper.cs index 148792b447..e4a2375d98 100644 --- a/src/Vogen/SemanticHelper.cs +++ b/src/Vogen/SemanticHelper.cs @@ -14,9 +14,10 @@ static class SemanticHelper var prefix = FullNamespace(symbol); var suffix = ""; + if (symbol.Arity > 0) { - suffix = $"<{string.Join(", ", symbol.TypeArguments.Select(targ => FullName((INamedTypeSymbol) targ)))}>"; + suffix = $"<{string.Join(", ", symbol.TypeArguments.Select(a => FullName(a as INamedTypeSymbol)))}>"; } if (prefix != "") diff --git a/tests/ConsumerTests/BugFixTests/Tests.cs b/tests/ConsumerTests/BugFixTests/Tests.cs new file mode 100644 index 0000000000..d051e49be8 --- /dev/null +++ b/tests/ConsumerTests/BugFixTests/Tests.cs @@ -0,0 +1,20 @@ +namespace ConsumerTests.BugFixTests; + +// There are no particular tests for this. The fact that it compiles without an issue +public class Test : Attribute { } + +[Test] +public class Foo { } + +[ValueObject] +public partial struct Vo { } + +public class Bar +{ + public Bar() + { + Vo.From(123); + } +} + + diff --git a/tests/SnapshotTests/BugFixes/Bug575_AttributesWithArraysBreaksGenerator.cs b/tests/SnapshotTests/BugFixes/Bug575_AttributesWithArraysBreaksGenerator.cs new file mode 100644 index 0000000000..e2763ddd8f --- /dev/null +++ b/tests/SnapshotTests/BugFixes/Bug575_AttributesWithArraysBreaksGenerator.cs @@ -0,0 +1,48 @@ +using System.Threading.Tasks; +using Shared; +using VerifyXunit; +using Vogen; + +namespace SnapshotTests.BugFixes; + +// See https://github.com/SteveDunn/Vogen/issues/575 +[UsesVerify] +public class Bug575_AttributesWithArraysBreaksGenerator +{ + // Previously, any attribute found with an array as a parameter caused an + // InvalidCastException in Vogen and stopped the generator. + [Fact] + public async Task Test() + { + var source = """ + + using System; + using Vogen; + + public class Test : Attribute { } + + [Test] + public class Test + { + Test() => Vo.From(123); + } + + [ValueObject] + public partial struct Vo + { + } + + + """; + + await RunTest(source); + } + + + private static Task RunTest(string source) => + new SnapshotRunner() + .WithSource(source) + .IgnoreInitialCompilationErrors() + .RunOnAllFrameworks(); + +} \ No newline at end of file diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-v3.1/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-v3.1/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt new file mode 100644 index 0000000000..afe16f8de4 --- /dev/null +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-v3.1/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt @@ -0,0 +1,427 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a source generator named Vogen (https://github.com/SteveDunn/Vogen) +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +// Suppress warnings about [Obsolete] member usage in generated code. +#pragma warning disable CS0618 + +// Suppress warnings for 'Override methods on comparable types'. +#pragma warning disable CA1036 + +// Suppress Error MA0097 : A class that implements IComparable or IComparable should override comparison operators +#pragma warning disable MA0097 + +// Suppress warning for 'The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.' +// The generator copies signatures from the BCL, e.g. for `TryParse`, and some of those have nullable annotations. +#pragma warning disable CS8669 + +// Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' +#pragma warning disable CS1591 + +using Vogen; + + + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(VoSystemTextJsonConverter))] +[global::System.ComponentModel.TypeConverter(typeof(VoTypeConverter))] + + [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(VoDebugView))] + [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: System.Int32, Value = { _value }")] + public partial struct Vo : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable + { +#if DEBUG + private readonly global::System.Diagnostics.StackTrace _stackTrace = null; +#endif + + private readonly global::System.Boolean _isInitialized; + + private readonly System.Int32 _value; + + /// + /// Gets the underlying value if set, otherwise a is thrown. + /// + public readonly System.Int32 Value + { + [global::System.Diagnostics.DebuggerStepThroughAttribute] + get + { + EnsureInitialized(); + return _value; + } + } + + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public Vo() + { +#if DEBUG + _stackTrace = new global::System.Diagnostics.StackTrace(); +#endif + + _isInitialized = false; + _value = default; + } + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + private Vo(System.Int32 value) + { + _value = value; + _isInitialized = true; + } + + /// + /// Builds an instance from the provided underlying type. + /// + /// The underlying type. + /// An instance of this type. + public static Vo From(System.Int32 value) + { + + + + + Vo instance = new Vo(value); + + return instance; + } + + + public static explicit operator Vo(System.Int32 value) => From(value); + public static explicit operator System.Int32(Vo value) => value.Value; + + // only called internally when something has been deserialized into + // its primitive type. + private static Vo Deserialize(System.Int32 value) + { + + + + + return new Vo(value); + } + public readonly global::System.Boolean Equals(Vo other) + { + // It's possible to create uninitialized instances via converters such as EfCore (HasDefaultValue), which call Equals. + // We treat anything uninitialized as not equal to anything, even other uninitialized instances of this type. + if(!_isInitialized || !other._isInitialized) return false; + + return global::System.Collections.Generic.EqualityComparer.Default.Equals(Value, other.Value); + } + public global::System.Boolean Equals(Vo other, global::System.Collections.Generic.IEqualityComparer comparer) + { + return comparer.Equals(this, other); + } + + + public readonly global::System.Boolean Equals(System.Int32 primitive) + { + return Value.Equals(primitive); + } + + public readonly override global::System.Boolean Equals(global::System.Object obj) + { + return obj is Vo && Equals((Vo) obj); + } + + public static global::System.Boolean operator ==(Vo left, Vo right) => Equals(left, right); + public static global::System.Boolean operator !=(Vo left, Vo right) => !(left == right); + + public static global::System.Boolean operator ==(Vo left, System.Int32 right) => Equals(left.Value, right); + public static global::System.Boolean operator !=(Vo left, System.Int32 right) => !Equals(left.Value, right); + + public static global::System.Boolean operator ==(System.Int32 left, Vo right) => Equals(left, right.Value); + public static global::System.Boolean operator !=(System.Int32 left, Vo right) => !Equals(left, right.Value); + + public int CompareTo(Vo other) => Value.CompareTo(other.Value); + public int CompareTo(object other) { + if(other is null) return 1; + if(other is Vo x) return CompareTo(x); + throw new global::System.ArgumentException("Cannot compare to object as it is not of type Vo", nameof(other)); + } + + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s) { + var r = System.Int32.Parse(s); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style) { + var r = System.Int32.Parse(s, style); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, provider); + return From(r); + } + + + + public readonly override global::System.Int32 GetHashCode() + { + return global::System.Collections.Generic.EqualityComparer.Default.GetHashCode(Value); + } + + /// Returns the string representation of the underlying type + /// + public readonly override global::System.String ToString() =>_isInitialized ? Value.ToString() : "[UNINITIALIZED]"; + + private readonly void EnsureInitialized() + { + if (!_isInitialized) + { +#if DEBUG + global::System.String message = "Use of uninitialized Value Object at: " + _stackTrace ?? ""; +#else + global::System.String message = "Use of uninitialized Value Object."; +#endif + + throw new global::Vogen.ValueObjectValidationException(message); + } + } + + + + + class VoSystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter + { + public override Vo Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { +#if NET5_0_OR_GREATER + return Vo.Deserialize( + options.NumberHandling == global::System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString && reader.TokenType == global::System.Text.Json.JsonTokenType.String + ? global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture) + : reader.GetInt32() + ); +#else + return Vo.Deserialize(reader.GetInt32()); +#endif + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + +#if NET6_0_OR_GREATER + public override Vo ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return Vo.Deserialize(global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif + } + + + class VoTypeConverter : global::System.ComponentModel.TypeConverter + { + public override global::System.Boolean CanConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertFrom(context, sourceType); + } + + public override global::System.Object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value) + { + return value switch + { + global::System.Int32 intValue => Vo.Deserialize(intValue), + global::System.String stringValue when !global::System.String.IsNullOrEmpty(stringValue) && global::System.Int32.TryParse(stringValue, out var result) => Vo.Deserialize(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value, global::System.Type destinationType) + { + if (value is Vo idValue) + { + if (destinationType == typeof(global::System.Int32)) + { + return idValue.Value; + } + + if (destinationType == typeof(global::System.String)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + + + + + + internal sealed class VoDebugView + { + private readonly Vo _t; + + VoDebugView(Vo t) + { + _t = t; + } + + public global::System.Boolean IsInitialized => _t._isInitialized; + public global::System.String UnderlyingType => "System.Int32"; + public global::System.String Value => _t._isInitialized ? _t._value.ToString() : "[not initialized]" ; + + #if DEBUG + public global::System.String CreatedWith => _t._stackTrace?.ToString() ?? "the From method"; + #endif + + public global::System.String Conversions => @"Default"; + } + +} + diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-v4.6.1/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-v4.6.1/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt new file mode 100644 index 0000000000..6aee5a1ddf --- /dev/null +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-v4.6.1/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt @@ -0,0 +1,371 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a source generator named Vogen (https://github.com/SteveDunn/Vogen) +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +// Suppress warnings about [Obsolete] member usage in generated code. +#pragma warning disable CS0618 + +// Suppress warnings for 'Override methods on comparable types'. +#pragma warning disable CA1036 + +// Suppress Error MA0097 : A class that implements IComparable or IComparable should override comparison operators +#pragma warning disable MA0097 + +// Suppress warning for 'The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.' +// The generator copies signatures from the BCL, e.g. for `TryParse`, and some of those have nullable annotations. +#pragma warning disable CS8669 + +// Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' +#pragma warning disable CS1591 + +using Vogen; + + + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(VoSystemTextJsonConverter))] +[global::System.ComponentModel.TypeConverter(typeof(VoTypeConverter))] + + [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(VoDebugView))] + [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: System.Int32, Value = { _value }")] + public partial struct Vo : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable + { +#if DEBUG + private readonly global::System.Diagnostics.StackTrace _stackTrace = null; +#endif + + private readonly global::System.Boolean _isInitialized; + + private readonly System.Int32 _value; + + /// + /// Gets the underlying value if set, otherwise a is thrown. + /// + public readonly System.Int32 Value + { + [global::System.Diagnostics.DebuggerStepThroughAttribute] + get + { + EnsureInitialized(); + return _value; + } + } + + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public Vo() + { +#if DEBUG + _stackTrace = new global::System.Diagnostics.StackTrace(); +#endif + + _isInitialized = false; + _value = default; + } + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + private Vo(System.Int32 value) + { + _value = value; + _isInitialized = true; + } + + /// + /// Builds an instance from the provided underlying type. + /// + /// The underlying type. + /// An instance of this type. + public static Vo From(System.Int32 value) + { + + + + + Vo instance = new Vo(value); + + return instance; + } + + + public static explicit operator Vo(System.Int32 value) => From(value); + public static explicit operator System.Int32(Vo value) => value.Value; + + // only called internally when something has been deserialized into + // its primitive type. + private static Vo Deserialize(System.Int32 value) + { + + + + + return new Vo(value); + } + public readonly global::System.Boolean Equals(Vo other) + { + // It's possible to create uninitialized instances via converters such as EfCore (HasDefaultValue), which call Equals. + // We treat anything uninitialized as not equal to anything, even other uninitialized instances of this type. + if(!_isInitialized || !other._isInitialized) return false; + + return global::System.Collections.Generic.EqualityComparer.Default.Equals(Value, other.Value); + } + public global::System.Boolean Equals(Vo other, global::System.Collections.Generic.IEqualityComparer comparer) + { + return comparer.Equals(this, other); + } + + + public readonly global::System.Boolean Equals(System.Int32 primitive) + { + return Value.Equals(primitive); + } + + public readonly override global::System.Boolean Equals(global::System.Object obj) + { + return obj is Vo && Equals((Vo) obj); + } + + public static global::System.Boolean operator ==(Vo left, Vo right) => Equals(left, right); + public static global::System.Boolean operator !=(Vo left, Vo right) => !(left == right); + + public static global::System.Boolean operator ==(Vo left, System.Int32 right) => Equals(left.Value, right); + public static global::System.Boolean operator !=(Vo left, System.Int32 right) => !Equals(left.Value, right); + + public static global::System.Boolean operator ==(System.Int32 left, Vo right) => Equals(left, right.Value); + public static global::System.Boolean operator !=(System.Int32 left, Vo right) => !Equals(left, right.Value); + + public int CompareTo(Vo other) => Value.CompareTo(other.Value); + public int CompareTo(object other) { + if(other is null) return 1; + if(other is Vo x) return CompareTo(x); + throw new global::System.ArgumentException("Cannot compare to object as it is not of type Vo", nameof(other)); + } + + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s) { + var r = System.Int32.Parse(s); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style) { + var r = System.Int32.Parse(s, style); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, provider); + return From(r); + } + + + + public readonly override global::System.Int32 GetHashCode() + { + return global::System.Collections.Generic.EqualityComparer.Default.GetHashCode(Value); + } + + /// Returns the string representation of the underlying type + /// + public readonly override global::System.String ToString() =>_isInitialized ? Value.ToString() : "[UNINITIALIZED]"; + + private readonly void EnsureInitialized() + { + if (!_isInitialized) + { +#if DEBUG + global::System.String message = "Use of uninitialized Value Object at: " + _stackTrace ?? ""; +#else + global::System.String message = "Use of uninitialized Value Object."; +#endif + + throw new global::Vogen.ValueObjectValidationException(message); + } + } + + + + + class VoSystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter + { + public override Vo Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { +#if NET5_0_OR_GREATER + return Vo.Deserialize( + options.NumberHandling == global::System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString && reader.TokenType == global::System.Text.Json.JsonTokenType.String + ? global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture) + : reader.GetInt32() + ); +#else + return Vo.Deserialize(reader.GetInt32()); +#endif + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + +#if NET6_0_OR_GREATER + public override Vo ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return Vo.Deserialize(global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif + } + + + class VoTypeConverter : global::System.ComponentModel.TypeConverter + { + public override global::System.Boolean CanConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertFrom(context, sourceType); + } + + public override global::System.Object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value) + { + return value switch + { + global::System.Int32 intValue => Vo.Deserialize(intValue), + global::System.String stringValue when !global::System.String.IsNullOrEmpty(stringValue) && global::System.Int32.TryParse(stringValue, out var result) => Vo.Deserialize(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value, global::System.Type destinationType) + { + if (value is Vo idValue) + { + if (destinationType == typeof(global::System.Int32)) + { + return idValue.Value; + } + + if (destinationType == typeof(global::System.String)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + + + + + + internal sealed class VoDebugView + { + private readonly Vo _t; + + VoDebugView(Vo t) + { + _t = t; + } + + public global::System.Boolean IsInitialized => _t._isInitialized; + public global::System.String UnderlyingType => "System.Int32"; + public global::System.String Value => _t._isInitialized ? _t._value.ToString() : "[not initialized]" ; + + #if DEBUG + public global::System.String CreatedWith => _t._stackTrace?.ToString() ?? "the From method"; + #endif + + public global::System.String Conversions => @"Default"; + } + +} + diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-v4.8/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-v4.8/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt new file mode 100644 index 0000000000..d971ff8269 --- /dev/null +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-v4.8/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt @@ -0,0 +1,371 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a source generator named Vogen (https://github.com/SteveDunn/Vogen) +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +// Suppress warnings about [Obsolete] member usage in generated code. +#pragma warning disable CS0618 + +// Suppress warnings for 'Override methods on comparable types'. +#pragma warning disable CA1036 + +// Suppress Error MA0097 : A class that implements IComparable or IComparable should override comparison operators +#pragma warning disable MA0097 + +// Suppress warning for 'The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.' +// The generator copies signatures from the BCL, e.g. for `TryParse`, and some of those have nullable annotations. +#pragma warning disable CS8669 + +// Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' +#pragma warning disable CS1591 + +using Vogen; + + + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(VoSystemTextJsonConverter))] +[global::System.ComponentModel.TypeConverter(typeof(VoTypeConverter))] + + [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(VoDebugView))] + [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: System.Int32, Value = { _value }")] + public partial struct Vo : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable + { +#if DEBUG + private readonly global::System.Diagnostics.StackTrace _stackTrace = null; +#endif + + private readonly global::System.Boolean _isInitialized; + + private readonly System.Int32 _value; + + /// + /// Gets the underlying value if set, otherwise a is thrown. + /// + public readonly System.Int32 Value + { + [global::System.Diagnostics.DebuggerStepThroughAttribute] + get + { + EnsureInitialized(); + return _value; + } + } + + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public Vo() + { +#if DEBUG + _stackTrace = new global::System.Diagnostics.StackTrace(); +#endif + + _isInitialized = false; + _value = default; + } + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + private Vo(System.Int32 value) + { + _value = value; + _isInitialized = true; + } + + /// + /// Builds an instance from the provided underlying type. + /// + /// The underlying type. + /// An instance of this type. + public static Vo From(System.Int32 value) + { + + + + + Vo instance = new Vo(value); + + return instance; + } + + + public static explicit operator Vo(System.Int32 value) => From(value); + public static explicit operator System.Int32(Vo value) => value.Value; + + // only called internally when something has been deserialized into + // its primitive type. + private static Vo Deserialize(System.Int32 value) + { + + + + + return new Vo(value); + } + public readonly global::System.Boolean Equals(Vo other) + { + // It's possible to create uninitialized instances via converters such as EfCore (HasDefaultValue), which call Equals. + // We treat anything uninitialized as not equal to anything, even other uninitialized instances of this type. + if(!_isInitialized || !other._isInitialized) return false; + + return global::System.Collections.Generic.EqualityComparer.Default.Equals(Value, other.Value); + } + public global::System.Boolean Equals(Vo other, global::System.Collections.Generic.IEqualityComparer comparer) + { + return comparer.Equals(this, other); + } + + + public readonly global::System.Boolean Equals(System.Int32 primitive) + { + return Value.Equals(primitive); + } + + public readonly override global::System.Boolean Equals(global::System.Object obj) + { + return obj is Vo && Equals((Vo) obj); + } + + public static global::System.Boolean operator ==(Vo left, Vo right) => Equals(left, right); + public static global::System.Boolean operator !=(Vo left, Vo right) => !(left == right); + + public static global::System.Boolean operator ==(Vo left, System.Int32 right) => Equals(left.Value, right); + public static global::System.Boolean operator !=(Vo left, System.Int32 right) => !Equals(left.Value, right); + + public static global::System.Boolean operator ==(System.Int32 left, Vo right) => Equals(left, right.Value); + public static global::System.Boolean operator !=(System.Int32 left, Vo right) => !Equals(left, right.Value); + + public int CompareTo(Vo other) => Value.CompareTo(other.Value); + public int CompareTo(object other) { + if(other is null) return 1; + if(other is Vo x) return CompareTo(x); + throw new global::System.ArgumentException("Cannot compare to object as it is not of type Vo", nameof(other)); + } + + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s) { + var r = System.Int32.Parse(s); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style) { + var r = System.Int32.Parse(s, style); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + + + public readonly override global::System.Int32 GetHashCode() + { + return global::System.Collections.Generic.EqualityComparer.Default.GetHashCode(Value); + } + + /// Returns the string representation of the underlying type + /// + public readonly override global::System.String ToString() =>_isInitialized ? Value.ToString() : "[UNINITIALIZED]"; + + private readonly void EnsureInitialized() + { + if (!_isInitialized) + { +#if DEBUG + global::System.String message = "Use of uninitialized Value Object at: " + _stackTrace ?? ""; +#else + global::System.String message = "Use of uninitialized Value Object."; +#endif + + throw new global::Vogen.ValueObjectValidationException(message); + } + } + + + + + class VoSystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter + { + public override Vo Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { +#if NET5_0_OR_GREATER + return Vo.Deserialize( + options.NumberHandling == global::System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString && reader.TokenType == global::System.Text.Json.JsonTokenType.String + ? global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture) + : reader.GetInt32() + ); +#else + return Vo.Deserialize(reader.GetInt32()); +#endif + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + +#if NET6_0_OR_GREATER + public override Vo ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return Vo.Deserialize(global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif + } + + + class VoTypeConverter : global::System.ComponentModel.TypeConverter + { + public override global::System.Boolean CanConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertFrom(context, sourceType); + } + + public override global::System.Object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value) + { + return value switch + { + global::System.Int32 intValue => Vo.Deserialize(intValue), + global::System.String stringValue when !global::System.String.IsNullOrEmpty(stringValue) && global::System.Int32.TryParse(stringValue, out var result) => Vo.Deserialize(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value, global::System.Type destinationType) + { + if (value is Vo idValue) + { + if (destinationType == typeof(global::System.Int32)) + { + return idValue.Value; + } + + if (destinationType == typeof(global::System.String)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + + + + + + internal sealed class VoDebugView + { + private readonly Vo _t; + + VoDebugView(Vo t) + { + _t = t; + } + + public global::System.Boolean IsInitialized => _t._isInitialized; + public global::System.String UnderlyingType => "System.Int32"; + public global::System.String Value => _t._isInitialized ? _t._value.ToString() : "[not initialized]" ; + + #if DEBUG + public global::System.String CreatedWith => _t._stackTrace?.ToString() ?? "the From method"; + #endif + + public global::System.String Conversions => @"Default"; + } + +} + diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-v5.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-v5.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt new file mode 100644 index 0000000000..afe16f8de4 --- /dev/null +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-v5.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt @@ -0,0 +1,427 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a source generator named Vogen (https://github.com/SteveDunn/Vogen) +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +// Suppress warnings about [Obsolete] member usage in generated code. +#pragma warning disable CS0618 + +// Suppress warnings for 'Override methods on comparable types'. +#pragma warning disable CA1036 + +// Suppress Error MA0097 : A class that implements IComparable or IComparable should override comparison operators +#pragma warning disable MA0097 + +// Suppress warning for 'The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.' +// The generator copies signatures from the BCL, e.g. for `TryParse`, and some of those have nullable annotations. +#pragma warning disable CS8669 + +// Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' +#pragma warning disable CS1591 + +using Vogen; + + + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(VoSystemTextJsonConverter))] +[global::System.ComponentModel.TypeConverter(typeof(VoTypeConverter))] + + [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(VoDebugView))] + [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: System.Int32, Value = { _value }")] + public partial struct Vo : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable + { +#if DEBUG + private readonly global::System.Diagnostics.StackTrace _stackTrace = null; +#endif + + private readonly global::System.Boolean _isInitialized; + + private readonly System.Int32 _value; + + /// + /// Gets the underlying value if set, otherwise a is thrown. + /// + public readonly System.Int32 Value + { + [global::System.Diagnostics.DebuggerStepThroughAttribute] + get + { + EnsureInitialized(); + return _value; + } + } + + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public Vo() + { +#if DEBUG + _stackTrace = new global::System.Diagnostics.StackTrace(); +#endif + + _isInitialized = false; + _value = default; + } + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + private Vo(System.Int32 value) + { + _value = value; + _isInitialized = true; + } + + /// + /// Builds an instance from the provided underlying type. + /// + /// The underlying type. + /// An instance of this type. + public static Vo From(System.Int32 value) + { + + + + + Vo instance = new Vo(value); + + return instance; + } + + + public static explicit operator Vo(System.Int32 value) => From(value); + public static explicit operator System.Int32(Vo value) => value.Value; + + // only called internally when something has been deserialized into + // its primitive type. + private static Vo Deserialize(System.Int32 value) + { + + + + + return new Vo(value); + } + public readonly global::System.Boolean Equals(Vo other) + { + // It's possible to create uninitialized instances via converters such as EfCore (HasDefaultValue), which call Equals. + // We treat anything uninitialized as not equal to anything, even other uninitialized instances of this type. + if(!_isInitialized || !other._isInitialized) return false; + + return global::System.Collections.Generic.EqualityComparer.Default.Equals(Value, other.Value); + } + public global::System.Boolean Equals(Vo other, global::System.Collections.Generic.IEqualityComparer comparer) + { + return comparer.Equals(this, other); + } + + + public readonly global::System.Boolean Equals(System.Int32 primitive) + { + return Value.Equals(primitive); + } + + public readonly override global::System.Boolean Equals(global::System.Object obj) + { + return obj is Vo && Equals((Vo) obj); + } + + public static global::System.Boolean operator ==(Vo left, Vo right) => Equals(left, right); + public static global::System.Boolean operator !=(Vo left, Vo right) => !(left == right); + + public static global::System.Boolean operator ==(Vo left, System.Int32 right) => Equals(left.Value, right); + public static global::System.Boolean operator !=(Vo left, System.Int32 right) => !Equals(left.Value, right); + + public static global::System.Boolean operator ==(System.Int32 left, Vo right) => Equals(left, right.Value); + public static global::System.Boolean operator !=(System.Int32 left, Vo right) => !Equals(left, right.Value); + + public int CompareTo(Vo other) => Value.CompareTo(other.Value); + public int CompareTo(object other) { + if(other is null) return 1; + if(other is Vo x) return CompareTo(x); + throw new global::System.ArgumentException("Cannot compare to object as it is not of type Vo", nameof(other)); + } + + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s) { + var r = System.Int32.Parse(s); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style) { + var r = System.Int32.Parse(s, style); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, provider); + return From(r); + } + + + + public readonly override global::System.Int32 GetHashCode() + { + return global::System.Collections.Generic.EqualityComparer.Default.GetHashCode(Value); + } + + /// Returns the string representation of the underlying type + /// + public readonly override global::System.String ToString() =>_isInitialized ? Value.ToString() : "[UNINITIALIZED]"; + + private readonly void EnsureInitialized() + { + if (!_isInitialized) + { +#if DEBUG + global::System.String message = "Use of uninitialized Value Object at: " + _stackTrace ?? ""; +#else + global::System.String message = "Use of uninitialized Value Object."; +#endif + + throw new global::Vogen.ValueObjectValidationException(message); + } + } + + + + + class VoSystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter + { + public override Vo Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { +#if NET5_0_OR_GREATER + return Vo.Deserialize( + options.NumberHandling == global::System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString && reader.TokenType == global::System.Text.Json.JsonTokenType.String + ? global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture) + : reader.GetInt32() + ); +#else + return Vo.Deserialize(reader.GetInt32()); +#endif + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + +#if NET6_0_OR_GREATER + public override Vo ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return Vo.Deserialize(global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif + } + + + class VoTypeConverter : global::System.ComponentModel.TypeConverter + { + public override global::System.Boolean CanConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertFrom(context, sourceType); + } + + public override global::System.Object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value) + { + return value switch + { + global::System.Int32 intValue => Vo.Deserialize(intValue), + global::System.String stringValue when !global::System.String.IsNullOrEmpty(stringValue) && global::System.Int32.TryParse(stringValue, out var result) => Vo.Deserialize(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value, global::System.Type destinationType) + { + if (value is Vo idValue) + { + if (destinationType == typeof(global::System.Int32)) + { + return idValue.Value; + } + + if (destinationType == typeof(global::System.String)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + + + + + + internal sealed class VoDebugView + { + private readonly Vo _t; + + VoDebugView(Vo t) + { + _t = t; + } + + public global::System.Boolean IsInitialized => _t._isInitialized; + public global::System.String UnderlyingType => "System.Int32"; + public global::System.String Value => _t._isInitialized ? _t._value.ToString() : "[not initialized]" ; + + #if DEBUG + public global::System.String CreatedWith => _t._stackTrace?.ToString() ?? "the From method"; + #endif + + public global::System.String Conversions => @"Default"; + } + +} + diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-v6.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-v6.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt new file mode 100644 index 0000000000..afe16f8de4 --- /dev/null +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-v6.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt @@ -0,0 +1,427 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a source generator named Vogen (https://github.com/SteveDunn/Vogen) +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +// Suppress warnings about [Obsolete] member usage in generated code. +#pragma warning disable CS0618 + +// Suppress warnings for 'Override methods on comparable types'. +#pragma warning disable CA1036 + +// Suppress Error MA0097 : A class that implements IComparable or IComparable should override comparison operators +#pragma warning disable MA0097 + +// Suppress warning for 'The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.' +// The generator copies signatures from the BCL, e.g. for `TryParse`, and some of those have nullable annotations. +#pragma warning disable CS8669 + +// Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' +#pragma warning disable CS1591 + +using Vogen; + + + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(VoSystemTextJsonConverter))] +[global::System.ComponentModel.TypeConverter(typeof(VoTypeConverter))] + + [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(VoDebugView))] + [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: System.Int32, Value = { _value }")] + public partial struct Vo : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable + { +#if DEBUG + private readonly global::System.Diagnostics.StackTrace _stackTrace = null; +#endif + + private readonly global::System.Boolean _isInitialized; + + private readonly System.Int32 _value; + + /// + /// Gets the underlying value if set, otherwise a is thrown. + /// + public readonly System.Int32 Value + { + [global::System.Diagnostics.DebuggerStepThroughAttribute] + get + { + EnsureInitialized(); + return _value; + } + } + + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public Vo() + { +#if DEBUG + _stackTrace = new global::System.Diagnostics.StackTrace(); +#endif + + _isInitialized = false; + _value = default; + } + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + private Vo(System.Int32 value) + { + _value = value; + _isInitialized = true; + } + + /// + /// Builds an instance from the provided underlying type. + /// + /// The underlying type. + /// An instance of this type. + public static Vo From(System.Int32 value) + { + + + + + Vo instance = new Vo(value); + + return instance; + } + + + public static explicit operator Vo(System.Int32 value) => From(value); + public static explicit operator System.Int32(Vo value) => value.Value; + + // only called internally when something has been deserialized into + // its primitive type. + private static Vo Deserialize(System.Int32 value) + { + + + + + return new Vo(value); + } + public readonly global::System.Boolean Equals(Vo other) + { + // It's possible to create uninitialized instances via converters such as EfCore (HasDefaultValue), which call Equals. + // We treat anything uninitialized as not equal to anything, even other uninitialized instances of this type. + if(!_isInitialized || !other._isInitialized) return false; + + return global::System.Collections.Generic.EqualityComparer.Default.Equals(Value, other.Value); + } + public global::System.Boolean Equals(Vo other, global::System.Collections.Generic.IEqualityComparer comparer) + { + return comparer.Equals(this, other); + } + + + public readonly global::System.Boolean Equals(System.Int32 primitive) + { + return Value.Equals(primitive); + } + + public readonly override global::System.Boolean Equals(global::System.Object obj) + { + return obj is Vo && Equals((Vo) obj); + } + + public static global::System.Boolean operator ==(Vo left, Vo right) => Equals(left, right); + public static global::System.Boolean operator !=(Vo left, Vo right) => !(left == right); + + public static global::System.Boolean operator ==(Vo left, System.Int32 right) => Equals(left.Value, right); + public static global::System.Boolean operator !=(Vo left, System.Int32 right) => !Equals(left.Value, right); + + public static global::System.Boolean operator ==(System.Int32 left, Vo right) => Equals(left, right.Value); + public static global::System.Boolean operator !=(System.Int32 left, Vo right) => !Equals(left, right.Value); + + public int CompareTo(Vo other) => Value.CompareTo(other.Value); + public int CompareTo(object other) { + if(other is null) return 1; + if(other is Vo x) return CompareTo(x); + throw new global::System.ArgumentException("Cannot compare to object as it is not of type Vo", nameof(other)); + } + + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s) { + var r = System.Int32.Parse(s); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style) { + var r = System.Int32.Parse(s, style); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, provider); + return From(r); + } + + + + public readonly override global::System.Int32 GetHashCode() + { + return global::System.Collections.Generic.EqualityComparer.Default.GetHashCode(Value); + } + + /// Returns the string representation of the underlying type + /// + public readonly override global::System.String ToString() =>_isInitialized ? Value.ToString() : "[UNINITIALIZED]"; + + private readonly void EnsureInitialized() + { + if (!_isInitialized) + { +#if DEBUG + global::System.String message = "Use of uninitialized Value Object at: " + _stackTrace ?? ""; +#else + global::System.String message = "Use of uninitialized Value Object."; +#endif + + throw new global::Vogen.ValueObjectValidationException(message); + } + } + + + + + class VoSystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter + { + public override Vo Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { +#if NET5_0_OR_GREATER + return Vo.Deserialize( + options.NumberHandling == global::System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString && reader.TokenType == global::System.Text.Json.JsonTokenType.String + ? global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture) + : reader.GetInt32() + ); +#else + return Vo.Deserialize(reader.GetInt32()); +#endif + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + +#if NET6_0_OR_GREATER + public override Vo ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return Vo.Deserialize(global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif + } + + + class VoTypeConverter : global::System.ComponentModel.TypeConverter + { + public override global::System.Boolean CanConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertFrom(context, sourceType); + } + + public override global::System.Object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value) + { + return value switch + { + global::System.Int32 intValue => Vo.Deserialize(intValue), + global::System.String stringValue when !global::System.String.IsNullOrEmpty(stringValue) && global::System.Int32.TryParse(stringValue, out var result) => Vo.Deserialize(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value, global::System.Type destinationType) + { + if (value is Vo idValue) + { + if (destinationType == typeof(global::System.Int32)) + { + return idValue.Value; + } + + if (destinationType == typeof(global::System.String)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + + + + + + internal sealed class VoDebugView + { + private readonly Vo _t; + + VoDebugView(Vo t) + { + _t = t; + } + + public global::System.Boolean IsInitialized => _t._isInitialized; + public global::System.String UnderlyingType => "System.Int32"; + public global::System.String Value => _t._isInitialized ? _t._value.ToString() : "[not initialized]" ; + + #if DEBUG + public global::System.String CreatedWith => _t._stackTrace?.ToString() ?? "the From method"; + #endif + + public global::System.String Conversions => @"Default"; + } + +} + diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-v7.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-v7.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt new file mode 100644 index 0000000000..1d4c4067ba --- /dev/null +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-v7.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt @@ -0,0 +1,483 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a source generator named Vogen (https://github.com/SteveDunn/Vogen) +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +// Suppress warnings about [Obsolete] member usage in generated code. +#pragma warning disable CS0618 + +// Suppress warnings for 'Override methods on comparable types'. +#pragma warning disable CA1036 + +// Suppress Error MA0097 : A class that implements IComparable or IComparable should override comparison operators +#pragma warning disable MA0097 + +// Suppress warning for 'The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.' +// The generator copies signatures from the BCL, e.g. for `TryParse`, and some of those have nullable annotations. +#pragma warning disable CS8669 + +// Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' +#pragma warning disable CS1591 + +using Vogen; + + + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(VoSystemTextJsonConverter))] +[global::System.ComponentModel.TypeConverter(typeof(VoTypeConverter))] + + [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(VoDebugView))] + [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: System.Int32, Value = { _value }")] + public partial struct Vo : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable, global::System.IParsable, global::System.ISpanParsable + { +#if DEBUG + private readonly global::System.Diagnostics.StackTrace _stackTrace = null; +#endif + + private readonly global::System.Boolean _isInitialized; + + private readonly System.Int32 _value; + + /// + /// Gets the underlying value if set, otherwise a is thrown. + /// + public readonly System.Int32 Value + { + [global::System.Diagnostics.DebuggerStepThroughAttribute] + get + { + EnsureInitialized(); + return _value; + } + } + + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public Vo() + { +#if DEBUG + _stackTrace = new global::System.Diagnostics.StackTrace(); +#endif + + _isInitialized = false; + _value = default; + } + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + private Vo(System.Int32 value) + { + _value = value; + _isInitialized = true; + } + + /// + /// Builds an instance from the provided underlying type. + /// + /// The underlying type. + /// An instance of this type. + public static Vo From(System.Int32 value) + { + + + + + Vo instance = new Vo(value); + + return instance; + } + + + public static explicit operator Vo(System.Int32 value) => From(value); + public static explicit operator System.Int32(Vo value) => value.Value; + + // only called internally when something has been deserialized into + // its primitive type. + private static Vo Deserialize(System.Int32 value) + { + + + + + return new Vo(value); + } + public readonly global::System.Boolean Equals(Vo other) + { + // It's possible to create uninitialized instances via converters such as EfCore (HasDefaultValue), which call Equals. + // We treat anything uninitialized as not equal to anything, even other uninitialized instances of this type. + if(!_isInitialized || !other._isInitialized) return false; + + return global::System.Collections.Generic.EqualityComparer.Default.Equals(Value, other.Value); + } + public global::System.Boolean Equals(Vo other, global::System.Collections.Generic.IEqualityComparer comparer) + { + return comparer.Equals(this, other); + } + + + public readonly global::System.Boolean Equals(System.Int32 primitive) + { + return Value.Equals(primitive); + } + + public readonly override global::System.Boolean Equals(global::System.Object obj) + { + return obj is Vo && Equals((Vo) obj); + } + + public static global::System.Boolean operator ==(Vo left, Vo right) => Equals(left, right); + public static global::System.Boolean operator !=(Vo left, Vo right) => !(left == right); + + public static global::System.Boolean operator ==(Vo left, System.Int32 right) => Equals(left.Value, right); + public static global::System.Boolean operator !=(Vo left, System.Int32 right) => !Equals(left.Value, right); + + public static global::System.Boolean operator ==(System.Int32 left, Vo right) => Equals(left, right.Value); + public static global::System.Boolean operator !=(System.Int32 left, Vo right) => !Equals(left, right.Value); + + public int CompareTo(Vo other) => Value.CompareTo(other.Value); + public int CompareTo(object other) { + if(other is null) return 1; + if(other is Vo x) return CompareTo(x); + throw new global::System.ArgumentException("Cannot compare to object as it is not of type Vo", nameof(other)); + } + + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(global::System.ReadOnlySpan s, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s) { + var r = System.Int32.Parse(s); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style) { + var r = System.Int32.Parse(s, style); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, provider); + return From(r); + } + + + + public readonly override global::System.Int32 GetHashCode() + { + return global::System.Collections.Generic.EqualityComparer.Default.GetHashCode(Value); + } + + /// Returns the string representation of the underlying type + /// + public readonly override global::System.String ToString() =>_isInitialized ? Value.ToString() : "[UNINITIALIZED]"; + + private readonly void EnsureInitialized() + { + if (!_isInitialized) + { +#if DEBUG + global::System.String message = "Use of uninitialized Value Object at: " + _stackTrace ?? ""; +#else + global::System.String message = "Use of uninitialized Value Object."; +#endif + + throw new global::Vogen.ValueObjectValidationException(message); + } + } + + + + + class VoSystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter + { + public override Vo Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { +#if NET5_0_OR_GREATER + return Vo.Deserialize( + options.NumberHandling == global::System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString && reader.TokenType == global::System.Text.Json.JsonTokenType.String + ? global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture) + : reader.GetInt32() + ); +#else + return Vo.Deserialize(reader.GetInt32()); +#endif + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + +#if NET6_0_OR_GREATER + public override Vo ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return Vo.Deserialize(global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif + } + + + class VoTypeConverter : global::System.ComponentModel.TypeConverter + { + public override global::System.Boolean CanConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertFrom(context, sourceType); + } + + public override global::System.Object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value) + { + return value switch + { + global::System.Int32 intValue => Vo.Deserialize(intValue), + global::System.String stringValue when !global::System.String.IsNullOrEmpty(stringValue) && global::System.Int32.TryParse(stringValue, out var result) => Vo.Deserialize(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value, global::System.Type destinationType) + { + if (value is Vo idValue) + { + if (destinationType == typeof(global::System.Int32)) + { + return idValue.Value; + } + + if (destinationType == typeof(global::System.String)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + + + + + + internal sealed class VoDebugView + { + private readonly Vo _t; + + VoDebugView(Vo t) + { + _t = t; + } + + public global::System.Boolean IsInitialized => _t._isInitialized; + public global::System.String UnderlyingType => "System.Int32"; + public global::System.String Value => _t._isInitialized ? _t._value.ToString() : "[not initialized]" ; + + #if DEBUG + public global::System.String CreatedWith => _t._stackTrace?.ToString() ?? "the From method"; + #endif + + public global::System.String Conversions => @"Default"; + } + +} + diff --git a/tests/SnapshotTests/BugFixes/snapshots/snap-v8.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt b/tests/SnapshotTests/BugFixes/snapshots/snap-v8.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt new file mode 100644 index 0000000000..6322313617 --- /dev/null +++ b/tests/SnapshotTests/BugFixes/snapshots/snap-v8.0/Bug575_AttributesWithArraysBreaksGenerator.Test.verified.txt @@ -0,0 +1,573 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a source generator named Vogen (https://github.com/SteveDunn/Vogen) +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +// Suppress warnings about [Obsolete] member usage in generated code. +#pragma warning disable CS0618 + +// Suppress warnings for 'Override methods on comparable types'. +#pragma warning disable CA1036 + +// Suppress Error MA0097 : A class that implements IComparable or IComparable should override comparison operators +#pragma warning disable MA0097 + +// Suppress warning for 'The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.' +// The generator copies signatures from the BCL, e.g. for `TryParse`, and some of those have nullable annotations. +#pragma warning disable CS8669 + +// Suppress warnings about CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' +#pragma warning disable CS1591 + +using Vogen; + + + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Vogen", "1.0.0.0")] + [global::System.Text.Json.Serialization.JsonConverter(typeof(VoSystemTextJsonConverter))] +[global::System.ComponentModel.TypeConverter(typeof(VoTypeConverter))] + + [global::System.Diagnostics.DebuggerTypeProxyAttribute(typeof(VoDebugView))] + [global::System.Diagnostics.DebuggerDisplayAttribute("Underlying type: System.Int32, Value = { _value }")] + public partial struct Vo : global::System.IEquatable, global::System.IEquatable, global::System.IComparable, global::System.IComparable, global::System.IParsable, global::System.ISpanParsable, global::System.IUtf8SpanParsable + { +#if DEBUG + private readonly global::System.Diagnostics.StackTrace _stackTrace = null; +#endif + + private readonly global::System.Boolean _isInitialized; + + private readonly System.Int32 _value; + + /// + /// Gets the underlying value if set, otherwise a is thrown. + /// + public readonly System.Int32 Value + { + [global::System.Diagnostics.DebuggerStepThroughAttribute] + get + { + EnsureInitialized(); + return _value; + } + } + + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public Vo() + { +#if DEBUG + _stackTrace = new global::System.Diagnostics.StackTrace(); +#endif + + _isInitialized = false; + _value = default; + } + + [global::System.Diagnostics.DebuggerStepThroughAttribute] + private Vo(System.Int32 value) + { + _value = value; + _isInitialized = true; + } + + /// + /// Builds an instance from the provided underlying type. + /// + /// The underlying type. + /// An instance of this type. + public static Vo From(System.Int32 value) + { + + + + + Vo instance = new Vo(value); + + return instance; + } + + + public static explicit operator Vo(System.Int32 value) => From(value); + public static explicit operator System.Int32(Vo value) => value.Value; + + // only called internally when something has been deserialized into + // its primitive type. + private static Vo Deserialize(System.Int32 value) + { + + + + + return new Vo(value); + } + public readonly global::System.Boolean Equals(Vo other) + { + // It's possible to create uninitialized instances via converters such as EfCore (HasDefaultValue), which call Equals. + // We treat anything uninitialized as not equal to anything, even other uninitialized instances of this type. + if(!_isInitialized || !other._isInitialized) return false; + + return global::System.Collections.Generic.EqualityComparer.Default.Equals(Value, other.Value); + } + public global::System.Boolean Equals(Vo other, global::System.Collections.Generic.IEqualityComparer comparer) + { + return comparer.Equals(this, other); + } + + + public readonly global::System.Boolean Equals(System.Int32 primitive) + { + return Value.Equals(primitive); + } + + public readonly override global::System.Boolean Equals(global::System.Object obj) + { + return obj is Vo && Equals((Vo) obj); + } + + public static global::System.Boolean operator ==(Vo left, Vo right) => Equals(left, right); + public static global::System.Boolean operator !=(Vo left, Vo right) => !(left == right); + + public static global::System.Boolean operator ==(Vo left, System.Int32 right) => Equals(left.Value, right); + public static global::System.Boolean operator !=(Vo left, System.Int32 right) => !Equals(left.Value, right); + + public static global::System.Boolean operator ==(System.Int32 left, Vo right) => Equals(left, right.Value); + public static global::System.Boolean operator !=(System.Int32 left, Vo right) => !Equals(left, right.Value); + + public int CompareTo(Vo other) => Value.CompareTo(other.Value); + public int CompareTo(object other) { + if(other is null) return 1; + if(other is Vo x) return CompareTo(x); + throw new global::System.ArgumentException("Cannot compare to object as it is not of type Vo", nameof(other)); + } + + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan utf8Text, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(utf8Text, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan utf8Text, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(utf8Text, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan utf8Text, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(utf8Text, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(global::System.ReadOnlySpan s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, style, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, global::System.IFormatProvider provider, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, provider, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// True if the value could a) be parsed by the underlying type, and b) passes any validation (after running any optional normalization). + /// + public static global::System.Boolean TryParse(string s, +#if NETCOREAPP3_0_OR_GREATER +[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out Vo result) { + if(System.Int32.TryParse(s, out var __v)) { + + + result = new Vo(__v); + return true; + } + + result = default; + return false; + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(global::System.ReadOnlySpan utf8Text, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(utf8Text, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(global::System.ReadOnlySpan utf8Text, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(utf8Text, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(global::System.ReadOnlySpan s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(global::System.ReadOnlySpan s, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s) { + var r = System.Int32.Parse(s); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style) { + var r = System.Int32.Parse(s, style); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.Globalization.NumberStyles style, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, style, provider); + return From(r); + } + + /// + /// + /// + /// + /// The value created via the method. + /// + /// Thrown when the value can be parsed, but is not valid. + public static Vo Parse(string s, global::System.IFormatProvider provider) { + var r = System.Int32.Parse(s, provider); + return From(r); + } + + + + public readonly override global::System.Int32 GetHashCode() + { + return global::System.Collections.Generic.EqualityComparer.Default.GetHashCode(Value); + } + + /// Returns the string representation of the underlying type + /// + public readonly override global::System.String ToString() =>_isInitialized ? Value.ToString() : "[UNINITIALIZED]"; + + private readonly void EnsureInitialized() + { + if (!_isInitialized) + { +#if DEBUG + global::System.String message = "Use of uninitialized Value Object at: " + _stackTrace ?? ""; +#else + global::System.String message = "Use of uninitialized Value Object."; +#endif + + throw new global::Vogen.ValueObjectValidationException(message); + } + } + + + + + class VoSystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter + { + public override Vo Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { +#if NET5_0_OR_GREATER + return Vo.Deserialize( + options.NumberHandling == global::System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString && reader.TokenType == global::System.Text.Json.JsonTokenType.String + ? global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture) + : reader.GetInt32() + ); +#else + return Vo.Deserialize(reader.GetInt32()); +#endif + } + + public override void Write(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } + +#if NET6_0_OR_GREATER + public override Vo ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return Vo.Deserialize(global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, Vo value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif + } + + + class VoTypeConverter : global::System.ComponentModel.TypeConverter + { + public override global::System.Boolean CanConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertFrom(context, sourceType); + } + + public override global::System.Object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value) + { + return value switch + { + global::System.Int32 intValue => Vo.Deserialize(intValue), + global::System.String stringValue when !global::System.String.IsNullOrEmpty(stringValue) && global::System.Int32.TryParse(stringValue, out var result) => Vo.Deserialize(result), + _ => base.ConvertFrom(context, culture, value), + }; + } + + public override bool CanConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) + { + return sourceType == typeof(global::System.Int32) || sourceType == typeof(global::System.String) || base.CanConvertTo(context, sourceType); + } + + public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value, global::System.Type destinationType) + { + if (value is Vo idValue) + { + if (destinationType == typeof(global::System.Int32)) + { + return idValue.Value; + } + + if (destinationType == typeof(global::System.String)) + { + return idValue.Value.ToString(); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + } + + + + + + + internal sealed class VoDebugView + { + private readonly Vo _t; + + VoDebugView(Vo t) + { + _t = t; + } + + public global::System.Boolean IsInitialized => _t._isInitialized; + public global::System.String UnderlyingType => "System.Int32"; + public global::System.String Value => _t._isInitialized ? _t._value.ToString() : "[not initialized]" ; + + #if DEBUG + public global::System.String CreatedWith => _t._stackTrace?.ToString() ?? "the From method"; + #endif + + public global::System.String Conversions => @"Default"; + } + +} +