File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
csharp/ql/test/library-tests/implicittostring Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+
3
+ public class TestImplicitToString
4
+ {
5
+ public class Container
6
+ {
7
+ public override string ToString ( )
8
+ {
9
+ return "Container" ;
10
+ }
11
+ }
12
+
13
+ public class FormattableContainer : IFormattable
14
+ {
15
+ public string ToString ( string format , IFormatProvider formatProvider )
16
+ {
17
+ return "Formatted container" ;
18
+ }
19
+
20
+
21
+ public override string ToString ( )
22
+ {
23
+ return "Container" ;
24
+ }
25
+ }
26
+
27
+ public void M ( )
28
+ {
29
+ var container = new Container ( ) ;
30
+
31
+ var y = "Hello" + container ; // Implicit ToString call
32
+ y = "Hello" + container . ToString ( ) ;
33
+ y = $ "Hello { container } "; // Implicit ToString() call
34
+ y = $ "Hello { container . ToString ( ) } ";
35
+ y = $ "Hello { container : D} "; // Implicit ToString() call.
36
+
37
+ var z = "Hello" + y ; // No implicit ToString call as `y` is already a string.
38
+
39
+ var formattableContainer = new FormattableContainer ( ) ;
40
+ y = "Hello" + formattableContainer ; // Implicit call to ToString().
41
+ y = $ "Hello { formattableContainer } "; // Implicit call to ToString(string, IFormatProvider). We don't handle this.
42
+ y = $ "Hello { formattableContainer : D} "; // Implicit call to ToString(string, IFormatProvider). We don't handle this.
43
+ }
44
+ }
Original file line number Diff line number Diff line change
1
+ | implicitToString.cs:31:27:31:35 | call to method ToString |
2
+ | implicitToString.cs:33:22:33:30 | call to method ToString |
3
+ | implicitToString.cs:35:22:35:30 | call to method ToString |
4
+ | implicitToString.cs:40:23:40:42 | call to method ToString |
Original file line number Diff line number Diff line change
1
+ import csharp
2
+
3
+ from MethodCall c
4
+ where c .isImplicit ( )
5
+ select c
You can’t perform that action at this time.
0 commit comments