-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a406b2
commit 0c5c2a3
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
csharp/ql/test/library-tests/implicittostring/implicitToString.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
|
||
public class TestImplicitToString | ||
{ | ||
public class Container | ||
{ | ||
public override string ToString() | ||
{ | ||
return "Container"; | ||
} | ||
} | ||
|
||
public class FormattableContainer : IFormattable | ||
{ | ||
public string ToString(string format, IFormatProvider formatProvider) | ||
{ | ||
return "Formatted container"; | ||
} | ||
|
||
|
||
public override string ToString() | ||
{ | ||
return "Container"; | ||
} | ||
} | ||
|
||
public void M() | ||
{ | ||
var container = new Container(); | ||
|
||
var y = "Hello" + container; // Implicit ToString call | ||
y = "Hello" + container.ToString(); | ||
y = $"Hello {container}"; // Implicit ToString() call | ||
y = $"Hello {container.ToString()}"; | ||
y = $"Hello {container:D}"; // Implicit ToString() call. | ||
|
||
var z = "Hello" + y; // No implicit ToString call as `y` is already a string. | ||
|
||
var formattableContainer = new FormattableContainer(); | ||
y = "Hello" + formattableContainer; // Implicit call to ToString(). | ||
y = $"Hello {formattableContainer}"; // Implicit call to ToString(string, IFormatProvider). We don't handle this. | ||
y = $"Hello {formattableContainer:D}"; // Implicit call to ToString(string, IFormatProvider). We don't handle this. | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
csharp/ql/test/library-tests/implicittostring/implicitToString.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
| implicitToString.cs:31:27:31:35 | call to method ToString | | ||
| implicitToString.cs:33:22:33:30 | call to method ToString | | ||
| implicitToString.cs:35:22:35:30 | call to method ToString | | ||
| implicitToString.cs:40:23:40:42 | call to method ToString | |
5 changes: 5 additions & 0 deletions
5
csharp/ql/test/library-tests/implicittostring/implicitToString.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import csharp | ||
|
||
from MethodCall c | ||
where c.isImplicit() | ||
select c |