Skip to content

Commit e6b40a4

Browse files
committed
C#: Add implicit to string test.
1 parent b3db77d commit e6b40a4

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
3+
public class TestImplicitToString
4+
{
5+
public class Container : IFormattable
6+
{
7+
public string ToString(string format, IFormatProvider formatProvider)
8+
{
9+
return "Formatted container";
10+
}
11+
12+
13+
public override string ToString()
14+
{
15+
return "Container";
16+
}
17+
}
18+
19+
public void M()
20+
{
21+
var x = new Container();
22+
23+
var y = "Hello" + x; // Implicit ToString call
24+
y = "Hello" + x.ToString();
25+
y = $"Hello {x}"; // Implicit ToString() call
26+
y = $"Hello {x.ToString()}";
27+
y = $"Hello {x:D}"; // Implicit ToString(string, IFormatProvider) call (we currently don't handle this)
28+
29+
var z = "Hello" + y; // No implicit ToString call as `y` is already a string.
30+
}
31+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| implicitToString.cs:23:27:23:27 | call to method ToString |
2+
| implicitToString.cs:25:22:25:22 | call to method ToString |
3+
| implicitToString.cs:27:22:27:22 | call to method ToString |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from MethodCall c
4+
where c.isImplicit()
5+
select c

0 commit comments

Comments
 (0)