-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathDefaultToString.cs
More file actions
50 lines (36 loc) · 1003 Bytes
/
DefaultToString.cs
File metadata and controls
50 lines (36 loc) · 1003 Bytes
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
using System;
using System.Text;
class DefaultToString
{
void M()
{
var d = new DefaultToString();
Console.WriteLine(d.ToString()); // BAD
var s = "hello " + d; // BAD
new A().ToString(); // GOOD
new B().ToString(); // GOOD
var ints = new int[] { 1, 2, 3 };
Console.WriteLine(ints); // BAD
Console.WriteLine(string.Join(", ", ints)); // GOOD
s = "hello " + ints; // BAD
s = "hello " + string.Join(", ", ints); // GOOD
s = "" + NullableE; // GOOD
E e = E.A;
Console.WriteLine(e); // GOOD
C c = new D();
Console.WriteLine(c); // GOOD
}
class A
{
override public string ToString() { return "hello"; }
}
class B : A { }
enum E { A, B }
E? NullableE { get; set; }
class C { }
class D : C
{
override public string ToString() { return "D"; }
}
}
// semmle-extractor-options: /r:System.Runtime.Extensions.dll