@@ -40,6 +40,36 @@ void M()
40
40
" , source , expected ) ;
41
41
}
42
42
43
+ [ Fact , Trait ( Traits . Analyzer , DiagnosticIdentifiers . UseElementAccess ) ]
44
+ public async Task Test_UseElementAccessInsteadOfFirst_DerivedFromList ( )
45
+ {
46
+ await VerifyDiagnosticAndFixAsync ( @"
47
+ using System.Linq;
48
+ using System.Collections.Generic;
49
+
50
+ class C : List<string>
51
+ {
52
+ void M()
53
+ {
54
+ var list = new C();
55
+ var x = list.[|First()|];
56
+ }
57
+ }
58
+ " , @"
59
+ using System.Linq;
60
+ using System.Collections.Generic;
61
+
62
+ class C : List<string>
63
+ {
64
+ void M()
65
+ {
66
+ var list = new C();
67
+ var x = list[0];
68
+ }
69
+ }
70
+ " ) ;
71
+ }
72
+
43
73
[ Theory , Trait ( Traits . Analyzer , DiagnosticIdentifiers . UseElementAccess ) ]
44
74
[ InlineData ( "((List<object>)x).[|ElementAt(1)|]" , "((List<object>)x)[1]" ) ]
45
75
[ InlineData ( "((IList<object>)x).[|ElementAt(1)|]" , "((IList<object>)x)[1]" ) ]
@@ -68,6 +98,36 @@ void M()
68
98
" , source , expected ) ;
69
99
}
70
100
101
+ [ Fact , Trait ( Traits . Analyzer , DiagnosticIdentifiers . UseElementAccess ) ]
102
+ public async Task Test_UseElementAccessInsteadOfElementAt_DerivedFromList ( )
103
+ {
104
+ await VerifyDiagnosticAndFixAsync ( @"
105
+ using System.Linq;
106
+ using System.Collections.Generic;
107
+
108
+ class C : List<string>
109
+ {
110
+ void M()
111
+ {
112
+ var list = new C();
113
+ var x = list.[|ElementAt(1)|];
114
+ }
115
+ }
116
+ " , @"
117
+ using System.Linq;
118
+ using System.Collections.Generic;
119
+
120
+ class C : List<string>
121
+ {
122
+ void M()
123
+ {
124
+ var list = new C();
125
+ var x = list[1];
126
+ }
127
+ }
128
+ " ) ;
129
+ }
130
+
71
131
[ Fact , Trait ( Traits . Analyzer , DiagnosticIdentifiers . UseElementAccess ) ]
72
132
public async Task TestNoDiagnostic_UseElementAccessInsteadOfElementAt ( )
73
133
{
0 commit comments