Skip to content

Commit 5f3c3bf

Browse files
committed
C#: Add some more generic types and methods.
1 parent c0b70af commit 5f3c3bf

File tree

3 files changed

+94
-63
lines changed

3 files changed

+94
-63
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
extensionTypeReceiverParameter
22
| extensions.cs:6:5:16:5 | extension(String) | extensions.cs:6:22:6:22 | s |
3-
| extensions.cs:25:5:28:5 | extension(Object)<Object> | file://:0:0:0:0 | t |
4-
| extensions.cs:25:5:28:5 | extension(String)<String> | file://:0:0:0:0 | t |
5-
| extensions.cs:25:5:28:5 | extension(T)`1 | extensions.cs:25:20:25:20 | t |
3+
| extensions.cs:25:5:34:5 | extension(Object)<Object> | file://:0:0:0:0 | t |
4+
| extensions.cs:25:5:34:5 | extension(String)<String> | file://:0:0:0:0 | t |
5+
| extensions.cs:25:5:34:5 | extension(T)`1 | extensions.cs:25:20:25:20 | t |
66
extensionTypeExtendedType
77
| extensions.cs:6:5:16:5 | extension(String) | string |
88
| extensions.cs:18:5:23:5 | extension(Object) | object |
9-
| extensions.cs:25:5:28:5 | extension(Object)<Object> | object |
10-
| extensions.cs:25:5:28:5 | extension(String)<String> | string |
11-
| extensions.cs:25:5:28:5 | extension(T)`1 | T |
9+
| extensions.cs:25:5:34:5 | extension(Object)<Object> | object |
10+
| extensions.cs:25:5:34:5 | extension(String)<String> | string |
11+
| extensions.cs:25:5:34:5 | extension(T)`1 | T |

csharp/ql/test/library-tests/extension/extensions.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ public static class MyExtensions
2424

2525
extension<T>(T t) where T : class
2626
{
27-
public bool GenericM() => t is not null;
27+
public bool GenericProp1 => t is not null;
28+
public bool GenericProp2 { get { return true; } set { } }
29+
public bool GenericM1() => t is not null;
30+
public void GenericM2<S>(S other) { }
31+
public void GenericStaticM1() { }
32+
public static void GenericStaticM2<S>(S other) { }
33+
public static T operator +(T a, T b) { return null; }
2834
}
2935
}
3036

@@ -76,12 +82,19 @@ public static void CallingExtensions()
7682
MyExtensions.get_Prop2(s);
7783
MyExtensions.set_Prop2(s, false);
7884
MyExtensions.get_StaticProp();
85+
}
7986

80-
// Calling generic extension method
87+
public static void CallingGenericExtensions()
88+
{
89+
var s = "Hello Generic World.";
8190
var o = new object();
82-
o.GenericM();
83-
s.GenericM();
84-
MyExtensions.GenericM(o);
85-
MyExtensions.GenericM(s);
91+
92+
// Calling generic extension method
93+
o.GenericM1();
94+
s.GenericM1();
95+
96+
// Calling the compiler generated static extension methods.
97+
MyExtensions.GenericM1(o);
98+
MyExtensions.GenericM1(s);
8699
}
87100
}

0 commit comments

Comments
 (0)