-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathExtensionEverything.cs
More file actions
110 lines (92 loc) · 1.93 KB
/
ExtensionEverything.cs
File metadata and controls
110 lines (92 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal static class EmptyGroups
{
extension(int)
{
}
extension(int x)
{
}
extension(int y)
{
}
extension<T>(IEnumerable<T>)
{
}
extension<T>(IEnumerable<T> x)
{
}
extension<T>(IEnumerable<T> y)
{
}
extension<TKey, TValue>(Dictionary<TKey, TValue>)
{
}
extension<TKey, TValue>(Dictionary<TKey, TValue> x)
{
}
extension<TKey, TValue>(Dictionary<TKey, TValue> y)
{
}
}
internal static class ExtensionEverything
{
extension<T>(ICollection<T> collection) where T : notnull
{
public bool IsEmpty => collection.Count == 0;
public int Test {
get {
return 42;
}
set {
}
}
public void AddIfNotNull(T item)
{
if (item != null)
{
collection.Add(item);
}
}
public T2 CastElementAt<T2>(int index) where T2 : T
{
return (T2)(object)collection.ElementAt(index);
}
public static void StaticExtension()
{
}
}
extension(ExtensionEverythingTestUseSites.Point point)
{
public double Magnitude => Math.Sqrt(point.X * point.X + point.Y * point.Y);
}
}
internal class ExtensionEverythingTestUseSites
{
public record struct Point(int X, int Y);
public static void TestExtensionProperty()
{
Point point = new Point(3, 4);
Console.WriteLine(point.X);
Console.WriteLine(point.Y);
// TODO implement use-site transformation
//Console.WriteLine(point.Magnitude);
}
public static void TestExtensionMethods()
{
List<string> collection = new List<string>();
// TODO implement use-site transformation
//Console.WriteLine(collection.IsEmpty);
collection.AddIfNotNull("Hello");
collection.AddIfNotNull(null);
//Console.WriteLine(collection.IsEmpty);
//Console.WriteLine(collection.Test);
//collection.Test = 100;
//List<string>.StaticExtension();
}
}
}