Skip to content

Commit 29bc5f2

Browse files
Merge pull request #3680 from icsharpcode/csharp14/extensions
Dedicated UI and Decompiler APIs for C# 14 extensions
2 parents 58c4cc9 + ade13f8 commit 29bc5f2

35 files changed

Lines changed: 792 additions & 227 deletions

ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
<Compile Include="TestCases\ILPretty\Issue3524.cs" />
157157
<Compile Include="TestCases\ILPretty\Issue3552.cs" />
158158
<Compile Include="TestCases\Pretty\ExpandParamsArgumentsDisabled.cs" />
159-
<Compile Include="TestCases\Pretty\ExtensionProperties.cs" />
159+
<Compile Include="TestCases\Pretty\ExtensionEverything.cs" />
160160
<Compile Include="TestCases\Pretty\Issue3452.cs" />
161161
<Compile Include="TestCases\Pretty\Issue3541.cs" />
162162
<Compile Include="TestCases\Pretty\Issue3571_C.cs" />

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public async Task Issue3598([ValueSource(nameof(roslyn4OrNewerOptions))] Compile
560560
}
561561

562562
[Test]
563-
public async Task ExtensionProperties([ValueSource(nameof(roslyn4OrNewerOptions))] CompilerOptions cscOptions)
563+
public async Task ExtensionEverything([ValueSource(nameof(roslyn4OrNewerOptions))] CompilerOptions cscOptions)
564564
{
565565
await RunForLibrary(cscOptions: cscOptions | CompilerOptions.Preview | CompilerOptions.NullableEnable);
566566
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
6+
{
7+
internal static class EmptyGroups
8+
{
9+
extension(int)
10+
{
11+
}
12+
13+
extension(int x)
14+
{
15+
}
16+
17+
extension(int y)
18+
{
19+
}
20+
21+
extension<T>(IEnumerable<T>)
22+
{
23+
}
24+
25+
extension<T>(IEnumerable<T> x)
26+
{
27+
}
28+
29+
extension<T>(IEnumerable<T> y)
30+
{
31+
}
32+
33+
extension<TKey, TValue>(Dictionary<TKey, TValue>)
34+
{
35+
}
36+
37+
extension<TKey, TValue>(Dictionary<TKey, TValue> x)
38+
{
39+
}
40+
41+
extension<TKey, TValue>(Dictionary<TKey, TValue> y)
42+
{
43+
}
44+
}
45+
46+
internal static class ExtensionEverything
47+
{
48+
extension<T>(ICollection<T> collection) where T : notnull
49+
{
50+
public bool IsEmpty => collection.Count == 0;
51+
52+
public int Test {
53+
get {
54+
return 42;
55+
}
56+
set {
57+
}
58+
}
59+
60+
public void AddIfNotNull(T item)
61+
{
62+
if (item != null)
63+
{
64+
collection.Add(item);
65+
}
66+
}
67+
68+
public T2 CastElementAt<T2>(int index) where T2 : T
69+
{
70+
return (T2)(object)collection.ElementAt(index);
71+
}
72+
73+
public static void StaticExtension()
74+
{
75+
}
76+
}
77+
78+
extension(ExtensionEverythingTestUseSites.Point point)
79+
{
80+
public double Magnitude => Math.Sqrt(point.X * point.X + point.Y * point.Y);
81+
}
82+
}
83+
84+
internal class ExtensionEverythingTestUseSites
85+
{
86+
public record struct Point(int X, int Y);
87+
88+
public static void TestExtensionProperty()
89+
{
90+
Point point = new Point(3, 4);
91+
Console.WriteLine(point.X);
92+
Console.WriteLine(point.Y);
93+
// TODO implement use-site transformation
94+
//Console.WriteLine(point.Magnitude);
95+
}
96+
97+
public static void TestExtensionMethods()
98+
{
99+
List<string> collection = new List<string>();
100+
// TODO implement use-site transformation
101+
//Console.WriteLine(collection.IsEmpty);
102+
collection.AddIfNotNull("Hello");
103+
collection.AddIfNotNull(null);
104+
//Console.WriteLine(collection.IsEmpty);
105+
//Console.WriteLine(collection.Test);
106+
//collection.Test = 100;
107+
//List<string>.StaticExtension();
108+
}
109+
}
110+
}

ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExtensionProperties.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)