You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_sb.Append(" : throw new global::System.InvalidOperationException($\"'{nameof(").AppendTypeFullyQualified(_state).Append(")}' is not of type '").AppendTypeMinimallyQualified(memberType).Append("'.\");");
1046
+
_sb.Append(" : throw new global::System.InvalidOperationException($\"'{nameof(").AppendTypeFullyQualified(_state).Append(")}' is not of type '").AppendTypeMinimallyQualified(memberType).Append("' but of type '{GetMemberTypeName()}'.\");");
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_3_types_file=Thinktecture.Tests.TestUnion.AdHocUnion.g.cs.verified.txt
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -47,19 +47,31 @@ namespace Thinktecture.Tests
47
47
/// Gets the current value as <see cref="string"/>.
48
48
/// </summary>
49
49
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="string"/>.</exception>
50
-
public string AsString => IsString ? this._string! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string'.");
50
+
public string AsString => IsString ? this._string! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string' but of type '{GetMemberTypeName()}'.");
51
51
52
52
/// <summary>
53
53
/// Gets the current value as <see cref="int"/>.
54
54
/// </summary>
55
55
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="int"/>.</exception>
56
-
public int AsInt32 => IsInt32 ? this._int32 : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int'.");
56
+
public int AsInt32 => IsInt32 ? this._int32 : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int' but of type '{GetMemberTypeName()}'.");
57
57
58
58
/// <summary>
59
59
/// Gets the current value as <see cref="bool"/>.
60
60
/// </summary>
61
61
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="bool"/>.</exception>
62
-
public bool AsBoolean => IsBoolean ? this._boolean : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool'.");
62
+
public bool AsBoolean => IsBoolean ? this._boolean : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool' but of type '{GetMemberTypeName()}'.");
63
+
64
+
private string GetMemberTypeName()
65
+
{
66
+
return this._valueIndex switch
67
+
{
68
+
0 => "<uninitialized>",
69
+
1 => "string",
70
+
2 => "int",
71
+
3 => "bool",
72
+
_ => throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.")
73
+
};
74
+
}
63
75
64
76
/// <summary>
65
77
/// Gets the current value as <see cref="object"/>.
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_4_types_file=Thinktecture.Tests.TestUnion.AdHocUnion.g.cs.verified.txt
+17-4Lines changed: 17 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -54,25 +54,38 @@ namespace Thinktecture.Tests
54
54
/// Gets the current value as <see cref="string"/>.
55
55
/// </summary>
56
56
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="string"/>.</exception>
57
-
public string AsString => IsString ? this._string! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string'.");
57
+
public string AsString => IsString ? this._string! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string' but of type '{GetMemberTypeName()}'.");
58
58
59
59
/// <summary>
60
60
/// Gets the current value as <see cref="int"/>.
61
61
/// </summary>
62
62
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="int"/>.</exception>
63
-
public int AsInt32 => IsInt32 ? this._int32 : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int'.");
63
+
public int AsInt32 => IsInt32 ? this._int32 : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int' but of type '{GetMemberTypeName()}'.");
64
64
65
65
/// <summary>
66
66
/// Gets the current value as <see cref="bool"/>.
67
67
/// </summary>
68
68
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="bool"/>.</exception>
69
-
public bool AsBoolean => IsBoolean ? this._boolean : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool'.");
69
+
public bool AsBoolean => IsBoolean ? this._boolean : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool' but of type '{GetMemberTypeName()}'.");
70
70
71
71
/// <summary>
72
72
/// Gets the current value as <see cref="global::System.Guid"/>.
73
73
/// </summary>
74
74
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="global::System.Guid"/>.</exception>
75
-
public global::System.Guid AsGuid => IsGuid ? this._guid : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'Guid'.");
75
+
public global::System.Guid AsGuid => IsGuid ? this._guid : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'Guid' but of type '{GetMemberTypeName()}'.");
76
+
77
+
private string GetMemberTypeName()
78
+
{
79
+
return this._valueIndex switch
80
+
{
81
+
0 => "<uninitialized>",
82
+
1 => "string",
83
+
2 => "int",
84
+
3 => "bool",
85
+
4 => "Guid",
86
+
_ => throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.")
87
+
};
88
+
}
76
89
77
90
/// <summary>
78
91
/// Gets the current value as <see cref="object"/>.
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_AdHocUnion_and_3_types_file=Thinktecture.Tests.TestUnion.AdHocUnion.g.cs.verified.txt
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -47,19 +47,31 @@ namespace Thinktecture.Tests
47
47
/// Gets the current value as <see cref="string"/>.
48
48
/// </summary>
49
49
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="string"/>.</exception>
50
-
public string AsString => IsString ? this._string! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string'.");
50
+
public string AsString => IsString ? this._string! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string' but of type '{GetMemberTypeName()}'.");
51
51
52
52
/// <summary>
53
53
/// Gets the current value as <see cref="int"/>.
54
54
/// </summary>
55
55
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="int"/>.</exception>
56
-
public int AsInt32 => IsInt32 ? this._int32 : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int'.");
56
+
public int AsInt32 => IsInt32 ? this._int32 : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int' but of type '{GetMemberTypeName()}'.");
57
57
58
58
/// <summary>
59
59
/// Gets the current value as <see cref="bool"/>.
60
60
/// </summary>
61
61
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="bool"/>.</exception>
62
-
public bool AsBoolean => IsBoolean ? this._boolean : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool'.");
62
+
public bool AsBoolean => IsBoolean ? this._boolean : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool' but of type '{GetMemberTypeName()}'.");
63
+
64
+
private string GetMemberTypeName()
65
+
{
66
+
return this._valueIndex switch
67
+
{
68
+
0 => "<uninitialized>",
69
+
1 => "string",
70
+
2 => "int",
71
+
3 => "bool",
72
+
_ => throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.")
73
+
};
74
+
}
63
75
64
76
/// <summary>
65
77
/// Gets the current value as <see cref="object"/>.
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_AdHocUnion_and_4_types_file=Thinktecture.Tests.TestUnion.AdHocUnion.g.cs.verified.txt
+17-4Lines changed: 17 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -54,25 +54,38 @@ namespace Thinktecture.Tests
54
54
/// Gets the current value as <see cref="string"/>.
55
55
/// </summary>
56
56
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="string"/>.</exception>
57
-
public string AsString => IsString ? this._string! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string'.");
57
+
public string AsString => IsString ? this._string! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string' but of type '{GetMemberTypeName()}'.");
58
58
59
59
/// <summary>
60
60
/// Gets the current value as <see cref="int"/>.
61
61
/// </summary>
62
62
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="int"/>.</exception>
63
-
public int AsInt32 => IsInt32 ? this._int32 : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int'.");
63
+
public int AsInt32 => IsInt32 ? this._int32 : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int' but of type '{GetMemberTypeName()}'.");
64
64
65
65
/// <summary>
66
66
/// Gets the current value as <see cref="bool"/>.
67
67
/// </summary>
68
68
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="bool"/>.</exception>
69
-
public bool AsBoolean => IsBoolean ? this._boolean : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool'.");
69
+
public bool AsBoolean => IsBoolean ? this._boolean : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool' but of type '{GetMemberTypeName()}'.");
70
70
71
71
/// <summary>
72
72
/// Gets the current value as <see cref="global::System.Guid"/>.
73
73
/// </summary>
74
74
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="global::System.Guid"/>.</exception>
75
-
public global::System.Guid AsGuid => IsGuid ? this._guid : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'Guid'.");
75
+
public global::System.Guid AsGuid => IsGuid ? this._guid : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'Guid' but of type '{GetMemberTypeName()}'.");
76
+
77
+
private string GetMemberTypeName()
78
+
{
79
+
return this._valueIndex switch
80
+
{
81
+
0 => "<uninitialized>",
82
+
1 => "string",
83
+
2 => "int",
84
+
3 => "bool",
85
+
4 => "Guid",
86
+
_ => throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.")
87
+
};
88
+
}
76
89
77
90
/// <summary>
78
91
/// Gets the current value as <see cref="object"/>.
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_all_5_custom_names_file=Thinktecture.Tests.TestUnion.AdHocUnion.g.cs.verified.txt
+19-5Lines changed: 19 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -61,31 +61,45 @@ namespace Thinktecture.Tests
61
61
/// Gets the current value as <see cref="string"/>.
62
62
/// </summary>
63
63
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="string"/>.</exception>
64
-
public string AsText => IsText ? this._text! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string'.");
64
+
public string AsText => IsText ? this._text! : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string' but of type '{GetMemberTypeName()}'.");
65
65
66
66
/// <summary>
67
67
/// Gets the current value as <see cref="int"/>.
68
68
/// </summary>
69
69
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="int"/>.</exception>
70
-
public int AsNumber => IsNumber ? this._number : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int'.");
70
+
public int AsNumber => IsNumber ? this._number : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'int' but of type '{GetMemberTypeName()}'.");
71
71
72
72
/// <summary>
73
73
/// Gets the current value as <see cref="bool"/>.
74
74
/// </summary>
75
75
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="bool"/>.</exception>
76
-
public bool AsFlag => IsFlag ? this._flag : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool'.");
76
+
public bool AsFlag => IsFlag ? this._flag : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'bool' but of type '{GetMemberTypeName()}'.");
77
77
78
78
/// <summary>
79
79
/// Gets the current value as <see cref="global::System.Guid"/>.
80
80
/// </summary>
81
81
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="global::System.Guid"/>.</exception>
82
-
public global::System.Guid AsId => IsId ? this._id : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'Guid'.");
82
+
public global::System.Guid AsId => IsId ? this._id : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'Guid' but of type '{GetMemberTypeName()}'.");
83
83
84
84
/// <summary>
85
85
/// Gets the current value as <see cref="char"/>.
86
86
/// </summary>
87
87
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <see cref="char"/>.</exception>
88
-
public char AsCharacter => IsCharacter ? this._character : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'char'.");
88
+
public char AsCharacter => IsCharacter ? this._character : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'char' but of type '{GetMemberTypeName()}'.");
89
+
90
+
private string GetMemberTypeName()
91
+
{
92
+
return this._valueIndex switch
93
+
{
94
+
0 => "<uninitialized>",
95
+
1 => "string",
96
+
2 => "int",
97
+
3 => "bool",
98
+
4 => "Guid",
99
+
5 => "char",
100
+
_ => throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.")
101
+
};
102
+
}
89
103
90
104
/// <summary>
91
105
/// Gets the current value as <see cref="object"/>.
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_all_nullable_reference_types_file=Thinktecture.Tests.TestUnion.AdHocUnion.g.cs.verified.txt
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -45,19 +45,31 @@ namespace Thinktecture.Tests
45
45
/// Gets the current value as <c>string?</c>.
46
46
/// </summary>
47
47
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <c>string?</c>.</exception>
48
-
public string? AsString => IsString ? ((string?)this._obj) : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string?'.");
48
+
public string? AsString => IsString ? ((string?)this._obj) : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'string?' but of type '{GetMemberTypeName()}'.");
49
49
50
50
/// <summary>
51
51
/// Gets the current value as <c>global::System.Collections.Generic.List<int>?</c>.
52
52
/// </summary>
53
53
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <c>global::System.Collections.Generic.List<int>?</c>.</exception>
54
-
public global::System.Collections.Generic.List<int>? AsListOfInt32 => IsListOfInt32 ? ((global::System.Collections.Generic.List<int>?)this._obj) : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'List<int>?'.");
54
+
public global::System.Collections.Generic.List<int>? AsListOfInt32 => IsListOfInt32 ? ((global::System.Collections.Generic.List<int>?)this._obj) : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'List<int>?' but of type '{GetMemberTypeName()}'.");
55
55
56
56
/// <summary>
57
57
/// Gets the current value as <c>object?</c>.
58
58
/// </summary>
59
59
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <c>object?</c>.</exception>
60
-
public object? AsObject => IsObject ? ((object?)this._obj) : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'object?'.");
60
+
public object? AsObject => IsObject ? ((object?)this._obj) : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type 'object?' but of type '{GetMemberTypeName()}'.");
61
+
62
+
private string GetMemberTypeName()
63
+
{
64
+
return this._valueIndex switch
65
+
{
66
+
0 => "<uninitialized>",
67
+
1 => "string?",
68
+
2 => "List<int>?",
69
+
3 => "object?",
70
+
_ => throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.")
71
+
};
72
+
}
61
73
62
74
/// <summary>
63
75
/// Gets the current value as <see cref="object"/>.
0 commit comments