Skip to content

Commit 15a8279

Browse files
committed
fix: don't expand value tuples
1 parent c25e8e1 commit 15a8279

13 files changed

Lines changed: 607 additions & 31 deletions

src/Thinktecture.Runtime.Extensions.SourceGenerator/Extensions/StringBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ private static StringBuilder AppendTypeForXmlComment(
541541
return sb;
542542
}
543543

544-
var hasProblematicCharsForXmlDocs = qualifiedTypeName.IndexOfAny(['<', '[', '?']) > -1;
544+
var hasProblematicCharsForXmlDocs = qualifiedTypeName.IndexOfAny(['<', '[', '?', '(']) > -1;
545545

546546
if (hasProblematicCharsForXmlDocs)
547547
{

src/Thinktecture.Runtime.Extensions.SourceGenerator/Extensions/TypeSymbolExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ namespace Thinktecture;
99
public static class TypeSymbolExtensions
1010
{
1111
private static readonly SymbolDisplayFormat _fullyQualifiedDisplayFormat = SymbolDisplayFormat.FullyQualifiedFormat
12-
.AddMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier)
13-
.AddMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.ExpandValueTuple);
12+
.AddMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier);
1413

1514
public static string ToFullyQualifiedDisplayString(this ITypeSymbol type)
1615
{

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/Extensions/NamedTypeSymbolExtensionsTests/GetValidateFactoryArgumentsReturnType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public class MyClass
238238
var result = type.GetValidateFactoryArgumentsReturnType();
239239

240240
result.Should().NotBeNull();
241-
result.Should().Be("global::System.ValueTuple<string, int>");
241+
result.Should().Be("(string, int)");
242242
}
243243

244244
[Fact]

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/Extensions/TypeSymbolExtensionsTests/ToFullyQualifiedDisplayString.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ public class MyClass
537537

538538
var result = type.ToFullyQualifiedDisplayString();
539539

540-
result.Should().Be("global::System.ValueTuple<int, string>");
540+
result.Should().Be("(int, string)");
541541
}
542542

543543
[Fact]
@@ -558,7 +558,7 @@ public class MyClass
558558

559559
var result = type.ToFullyQualifiedDisplayString();
560560

561-
result.Should().Be("global::System.ValueTuple<int, string>");
561+
result.Should().Be("(int Id, string Name)");
562562
}
563563

564564
[Fact]

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_tuple_types_file=Thinktecture.Tests.TestUnion.AdHocUnion.g.cs.verified.txt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ namespace Thinktecture.Tests
1515
{
1616
MemberTypes = new global::System.Collections.Generic.List<global::System.Type>
1717
{
18-
typeof(global::System.ValueTuple<int, string>),
18+
typeof((int, string)),
1919
typeof(bool)
2020
}
2121
.AsReadOnly()
2222
};
2323

2424
private readonly int _valueIndex;
2525

26-
private readonly global::System.ValueTuple<int, string> _valueTupleOfInt32String;
26+
private readonly (int, string) _valueTupleOfInt32String;
2727
private readonly bool _boolean;
2828

2929
/// <summary>
30-
/// Indication whether the current value is of type <c>global::System.ValueTuple&lt;int, string&gt;</c>.
30+
/// Indication whether the current value is of type <c>(int, string)</c>.
3131
/// </summary>
3232
public bool IsValueTupleOfInt32String => this._valueIndex == 1;
3333

@@ -37,10 +37,10 @@ namespace Thinktecture.Tests
3737
public bool IsBoolean => this._valueIndex == 2;
3838

3939
/// <summary>
40-
/// Gets the current value as <c>global::System.ValueTuple&lt;int, string&gt;</c>.
40+
/// Gets the current value as <c>(int, string)</c>.
4141
/// </summary>
42-
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <c>global::System.ValueTuple&lt;int, string&gt;</c>.</exception>
43-
public global::System.ValueTuple<int, string> AsValueTupleOfInt32String => IsValueTupleOfInt32String ? this._valueTupleOfInt32String : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type '(int, string)'.");
42+
/// <exception cref="global::System.InvalidOperationException">If the current value is not of type <c>(int, string)</c>.</exception>
43+
public (int, string) AsValueTupleOfInt32String => IsValueTupleOfInt32String ? this._valueTupleOfInt32String : throw new global::System.InvalidOperationException($"'{nameof(global::Thinktecture.Tests.TestUnion)}' is not of type '(int, string)'.");
4444

4545
/// <summary>
4646
/// Gets the current value as <see cref="bool"/>.
@@ -62,7 +62,7 @@ namespace Thinktecture.Tests
6262
/// Initializes new instance with <paramref name="valueTupleOfInt32String"/>.
6363
/// </summary>
6464
/// <param name="valueTupleOfInt32String">Value to create a new instance for.</param>
65-
public TestUnion(global::System.ValueTuple<int, string> @valueTupleOfInt32String)
65+
public TestUnion((int, string) @valueTupleOfInt32String)
6666
{
6767
this._valueTupleOfInt32String = @valueTupleOfInt32String;
6868
this._valueIndex = 1;
@@ -82,11 +82,11 @@ namespace Thinktecture.Tests
8282
/// <summary>
8383
/// Executes an action depending on the current value.
8484
/// </summary>
85-
/// <param name="valueTupleOfInt32String">The action to execute if the current value is of type <c>global::System.ValueTuple&lt;int, string&gt;</c>.</param>
85+
/// <param name="valueTupleOfInt32String">The action to execute if the current value is of type <c>(int, string)</c>.</param>
8686
/// <param name="boolean">The action to execute if the current value is of type <see cref="bool"/>.</param>
8787
[global::System.Diagnostics.DebuggerStepThroughAttribute]
8888
public void Switch(
89-
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Action<global::System.ValueTuple<int, string>> @valueTupleOfInt32String,
89+
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Action<(int, string)> @valueTupleOfInt32String,
9090
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Action<bool> @boolean)
9191
{
9292
switch (this._valueIndex)
@@ -108,12 +108,12 @@ namespace Thinktecture.Tests
108108
/// Executes an action depending on the current value.
109109
/// </summary>
110110
/// <param name="state">State to be passed to the callbacks.</param>
111-
/// <param name="valueTupleOfInt32String">The action to execute if the current value is of type <c>global::System.ValueTuple&lt;int, string&gt;</c>.</param>
111+
/// <param name="valueTupleOfInt32String">The action to execute if the current value is of type <c>(int, string)</c>.</param>
112112
/// <param name="boolean">The action to execute if the current value is of type <see cref="bool"/>.</param>
113113
[global::System.Diagnostics.DebuggerStepThroughAttribute]
114114
public void Switch<TState>(
115115
TState @state,
116-
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Action<TState, global::System.ValueTuple<int, string>> @valueTupleOfInt32String,
116+
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Action<TState, (int, string)> @valueTupleOfInt32String,
117117
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Action<TState, bool> @boolean)
118118
#if NET9_0_OR_GREATER
119119
where TState : allows ref struct
@@ -137,11 +137,11 @@ namespace Thinktecture.Tests
137137
/// <summary>
138138
/// Executes a function depending on the current value.
139139
/// </summary>
140-
/// <param name="valueTupleOfInt32String">The function to execute if the current value is of type <c>global::System.ValueTuple&lt;int, string&gt;</c>.</param>
140+
/// <param name="valueTupleOfInt32String">The function to execute if the current value is of type <c>(int, string)</c>.</param>
141141
/// <param name="boolean">The function to execute if the current value is of type <see cref="bool"/>.</param>
142142
[global::System.Diagnostics.DebuggerStepThroughAttribute]
143143
public TResult Switch<TResult>(
144-
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Func<global::System.ValueTuple<int, string>, TResult> @valueTupleOfInt32String,
144+
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Func<(int, string), TResult> @valueTupleOfInt32String,
145145
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Func<bool, TResult> @boolean)
146146
#if NET9_0_OR_GREATER
147147
where TResult : allows ref struct
@@ -164,12 +164,12 @@ namespace Thinktecture.Tests
164164
/// Executes a function depending on the current value.
165165
/// </summary>
166166
/// <param name="state">State to be passed to the callbacks.</param>
167-
/// <param name="valueTupleOfInt32String">The function to execute if the current value is of type <c>global::System.ValueTuple&lt;int, string&gt;</c>.</param>
167+
/// <param name="valueTupleOfInt32String">The function to execute if the current value is of type <c>(int, string)</c>.</param>
168168
/// <param name="boolean">The function to execute if the current value is of type <see cref="bool"/>.</param>
169169
[global::System.Diagnostics.DebuggerStepThroughAttribute]
170170
public TResult Switch<TState, TResult>(
171171
TState @state,
172-
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Func<TState, global::System.ValueTuple<int, string>, TResult> @valueTupleOfInt32String,
172+
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Func<TState, (int, string), TResult> @valueTupleOfInt32String,
173173
[global::JetBrains.Annotations.InstantHandleAttribute] global::System.Func<TState, bool, TResult> @boolean)
174174
#if NET9_0_OR_GREATER
175175
where TResult : allows ref struct
@@ -191,7 +191,7 @@ namespace Thinktecture.Tests
191191
/// <summary>
192192
/// Maps current value to an instance of type <typeparamref name="TResult"/>.
193193
/// </summary>
194-
/// <param name="valueTupleOfInt32String">The instance to return if the current value is of type <c>global::System.ValueTuple&lt;int, string&gt;</c>.</param>
194+
/// <param name="valueTupleOfInt32String">The instance to return if the current value is of type <c>(int, string)</c>.</param>
195195
/// <param name="boolean">The instance to return if the current value is of type <see cref="bool"/>.</param>
196196
[global::System.Diagnostics.DebuggerStepThroughAttribute]
197197
public TResult Map<TResult>(
@@ -213,11 +213,11 @@ namespace Thinktecture.Tests
213213
}
214214

215215
/// <summary>
216-
/// Implicit conversion from type <c>global::System.ValueTuple&lt;int, string&gt;</c>.
216+
/// Implicit conversion from type <c>(int, string)</c>.
217217
/// </summary>
218218
/// <param name="valueTupleOfInt32String">Value to convert from.</param>
219219
/// <returns>A new instance of <see cref="TestUnion"/> converted from <paramref name="valueTupleOfInt32String"/>.</returns>
220-
public static implicit operator global::Thinktecture.Tests.TestUnion(global::System.ValueTuple<int, string> @valueTupleOfInt32String)
220+
public static implicit operator global::Thinktecture.Tests.TestUnion((int, string) @valueTupleOfInt32String)
221221
{
222222
return new global::Thinktecture.Tests.TestUnion(@valueTupleOfInt32String);
223223
}
@@ -233,12 +233,12 @@ namespace Thinktecture.Tests
233233
}
234234

235235
/// <summary>
236-
/// Explicit conversion to type <c>global::System.ValueTuple&lt;int, string&gt;</c>.
236+
/// Explicit conversion to type <c>(int, string)</c>.
237237
/// </summary>
238238
/// <param name="obj">Object to convert.</param>
239-
/// <returns>Inner value of type <c>global::System.ValueTuple&lt;int, string&gt;</c>.</returns>
240-
/// <exception cref="System.InvalidOperationException">If the inner value is not a <c>global::System.ValueTuple&lt;int, string&gt;</c>.</exception>
241-
public static explicit operator global::System.ValueTuple<int, string>(global::Thinktecture.Tests.TestUnion obj)
239+
/// <returns>Inner value of type <c>(int, string)</c>.</returns>
240+
/// <exception cref="System.InvalidOperationException">If the inner value is not a <c>(int, string)</c>.</exception>
241+
public static explicit operator (int, string)(global::Thinktecture.Tests.TestUnion obj)
242242
{
243243
return obj.AsValueTupleOfInt32String;
244244
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// <auto-generated />
2+
#nullable enable
3+
4+
namespace Thinktecture.Tests;
5+
6+
partial class TestEnum :
7+
global::System.IComparable,
8+
global::System.IComparable<global::Thinktecture.Tests.TestEnum>
9+
{
10+
/// <inheritdoc />
11+
public int CompareTo(object? obj)
12+
{
13+
if(obj is null)
14+
return 1;
15+
16+
if(obj is not global::Thinktecture.Tests.TestEnum item)
17+
throw new global::System.ArgumentException("Argument must be of type \"TestEnum\".", nameof(obj));
18+
19+
return this.CompareTo(item);
20+
}
21+
22+
/// <inheritdoc />
23+
public int CompareTo(global::Thinktecture.Tests.TestEnum? obj)
24+
{
25+
if(obj is null)
26+
return 1;
27+
28+
return ((global::System.IComparable<int>)this.Key).CompareTo(obj.Key);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// <auto-generated />
2+
#nullable enable
3+
4+
namespace Thinktecture.Tests;
5+
6+
partial class TestEnum :
7+
global::System.Numerics.IComparisonOperators<global::Thinktecture.Tests.TestEnum, global::Thinktecture.Tests.TestEnum, bool>
8+
{
9+
/// <inheritdoc cref="global::System.Numerics.IComparisonOperators{TSelf, TOther, TResult}.op_LessThan(TSelf, TOther)" />
10+
public static bool operator <(global::Thinktecture.Tests.TestEnum left, global::Thinktecture.Tests.TestEnum right)
11+
{
12+
global::System.ArgumentNullException.ThrowIfNull(left);
13+
global::System.ArgumentNullException.ThrowIfNull(right);
14+
return left.Key < right.Key;
15+
}
16+
17+
/// <inheritdoc cref="global::System.Numerics.IComparisonOperators{TSelf, TOther, TResult}.op_LessThanOrEqual(TSelf, TOther)" />
18+
public static bool operator <=(global::Thinktecture.Tests.TestEnum left, global::Thinktecture.Tests.TestEnum right)
19+
{
20+
global::System.ArgumentNullException.ThrowIfNull(left);
21+
global::System.ArgumentNullException.ThrowIfNull(right);
22+
return left.Key <= right.Key;
23+
}
24+
25+
/// <inheritdoc cref="global::System.Numerics.IComparisonOperators{TSelf, TOther, TResult}.op_GreaterThan(TSelf, TOther)" />
26+
public static bool operator >(global::Thinktecture.Tests.TestEnum left, global::Thinktecture.Tests.TestEnum right)
27+
{
28+
global::System.ArgumentNullException.ThrowIfNull(left);
29+
global::System.ArgumentNullException.ThrowIfNull(right);
30+
return left.Key > right.Key;
31+
}
32+
33+
/// <inheritdoc cref="global::System.Numerics.IComparisonOperators{TSelf, TOther, TResult}.op_GreaterThanOrEqual(TSelf, TOther)" />
34+
public static bool operator >=(global::Thinktecture.Tests.TestEnum left, global::Thinktecture.Tests.TestEnum right)
35+
{
36+
global::System.ArgumentNullException.ThrowIfNull(left);
37+
global::System.ArgumentNullException.ThrowIfNull(right);
38+
return left.Key >= right.Key;
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// <auto-generated />
2+
#nullable enable
3+
4+
namespace Thinktecture.Tests;
5+
6+
partial class TestEnum :
7+
global::System.Numerics.IEqualityOperators<global::Thinktecture.Tests.TestEnum, global::Thinktecture.Tests.TestEnum, bool>
8+
{
9+
/// <summary>
10+
/// Compares two instances of <see cref="TestEnum"/>.
11+
/// </summary>
12+
/// <param name="obj">Instance to compare.</param>
13+
/// <param name="other">Another instance to compare.</param>
14+
/// <returns><c>true</c> if objects are equal; otherwise <c>false</c>.</returns>
15+
public static bool operator ==(global::Thinktecture.Tests.TestEnum? obj, global::Thinktecture.Tests.TestEnum? other)
16+
{
17+
return global::System.Object.ReferenceEquals(obj, other);
18+
}
19+
20+
/// <summary>
21+
/// Compares two instances of <see cref="TestEnum"/>.
22+
/// </summary>
23+
/// <param name="obj">Instance to compare.</param>
24+
/// <param name="other">Another instance to compare.</param>
25+
/// <returns><c>false</c> if objects are equal; otherwise <c>true</c>.</returns>
26+
public static bool operator !=(global::Thinktecture.Tests.TestEnum? obj, global::Thinktecture.Tests.TestEnum? other)
27+
{
28+
return !(obj == other);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// <auto-generated />
2+
#nullable enable
3+
4+
namespace Thinktecture.Tests;
5+
6+
partial class TestEnum :
7+
global::System.IFormattable
8+
{
9+
/// <inheritdoc />
10+
public string ToString(string? format, global::System.IFormatProvider? formatProvider = null)
11+
{
12+
return ((global::System.IFormattable)this.Key).ToString(format, formatProvider);
13+
}
14+
}

0 commit comments

Comments
 (0)