@@ -135,112 +135,6 @@ static void Main(string[] args)
135135 ) ;
136136 }
137137
138- [ TestMethod ]
139- public void UsageOfImplicitConversion_WithProperties_ProducesWarningMessage ( )
140- {
141- string source = @"
142- using System;
143- using System.Collections.Generic;
144- using System.Linq;
145-
146- namespace ConsoleApp1
147- {
148- internal class Pair(DateTimeOffset DateTimeOffset, DateTime DateTime);
149-
150- internal class Program
151- {
152- static void Main(string[] args)
153- {
154- Pair pair = new(DateTimeOffset.Now, DateTime.Now);
155- _ = pair.DateTimeOffset < pair.DateTime;
156- }
157- }
158- }" ;
159-
160- VerifyCSharpDiagnostic (
161- source ,
162- new DiagnosticResult
163- {
164- Id = "INTL0202" ,
165- Severity = DiagnosticSeverity . Warning ,
166- Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior" ,
167- Locations = [ new DiagnosticResultLocation ( "Test0.cs" , 14 , 29 ) ]
168- }
169- ) ;
170- }
171-
172- [ TestMethod ]
173- public void UsageOfImplicitConversion_WithPropertiesInLinq_ProducesWarningMessage ( )
174- {
175- string source = @"
176- using System;
177- using System.Collections.Generic;
178- using System.Linq;
179-
180- namespace ConsoleApp1
181- {
182- internal class Pair(DateTimeOffset DateTimeOffset, DateTime DateTime);
183-
184- internal class Program
185- {
186- static void Main(string[] args)
187- {
188- List<Pair> list = new(){ new(DateTimeOffset.Now, DateTime.Now) };
189- _ = list.Where(pair => pair.DateTimeOffset < pair.DateTime);
190- }
191- }
192- }" ;
193-
194- VerifyCSharpDiagnostic (
195- source ,
196- new DiagnosticResult
197- {
198- Id = "INTL0202" ,
199- Severity = DiagnosticSeverity . Warning ,
200- Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior" ,
201- Locations = [ new DiagnosticResultLocation ( "Test0.cs" , 14 , 42 ) ]
202- }
203- ) ;
204- }
205-
206- [ TestMethod ]
207- public void UsageOfImplicitConversion_InLinqWithVariables_ProducesWarningMessage ( )
208- {
209- string source = @"
210- using System;
211- using System.Collections.Generic;
212- using System.Linq;
213-
214- namespace ConsoleApp1
215- {
216- internal class Pair(DateTimeOffset DateTimeOffset, DateTime DateTime);
217-
218- internal class Program
219- {
220- static void Main(string[] args)
221- {
222- List<Pair> list = new(){ new(DateTimeOffset.Now, DateTime.Now) };
223- _ = list.Where(pair => {
224- DateTimeOffset first = pair.DateTimeOffset;
225- DateTime second = pair.DateTime;
226- return first < second;
227- });
228- }
229- }
230- }" ;
231-
232- VerifyCSharpDiagnostic (
233- source ,
234- new DiagnosticResult
235- {
236- Id = "INTL0202" ,
237- Severity = DiagnosticSeverity . Warning ,
238- Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior" ,
239- Locations = [ new DiagnosticResultLocation ( "Test0.cs" , 18 , 24 ) ]
240- }
241- ) ;
242- }
243-
244138 [ TestMethod ]
245139 public void UsageOfExplicitConversion_ProducesNothing ( )
246140 {
@@ -262,51 +156,6 @@ static void Main(string[] args)
262156
263157 }
264158
265- [ TestMethod ]
266- public void UsageInLambdaWithDateProperty_ProducesWarningMessage ( )
267- {
268- // This test matches the original issue scenario
269- string source = @"
270- using System;
271- using System.Linq;
272-
273- namespace Test
274- {
275- public class TimeEntry
276- {
277- public DateTimeOffset EndDate { get; set; }
278- public DateTimeOffset StartDate { get; set; }
279- }
280-
281- public class DataSource
282- {
283- public IQueryable<TimeEntry> GetQuery(DateTime startDate, DateTime endDate)
284- {
285- return Enumerable.Empty<TimeEntry>().AsQueryable()
286- .Where(te =>
287- te.EndDate <= endDate.Date.AddDays(1).AddTicks(-1) &&
288- te.StartDate >= startDate.Date);
289- }
290- }
291- }" ;
292-
293- VerifyCSharpDiagnostic ( source ,
294- new DiagnosticResult
295- {
296- Id = "INTL0202" ,
297- Severity = DiagnosticSeverity . Warning ,
298- Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior" ,
299- Locations = [ new DiagnosticResultLocation ( "Test0.cs" , 18 , 35 ) ]
300- } ,
301- new DiagnosticResult
302- {
303- Id = "INTL0202" ,
304- Severity = DiagnosticSeverity . Warning ,
305- Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior" ,
306- Locations = [ new DiagnosticResultLocation ( "Test0.cs" , 19 , 38 ) ]
307- } ) ;
308- }
309-
310159 protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer ( )
311160 {
312161 return new Analyzers . BanImplicitDateTimeToDateTimeOffsetConversion ( ) ;
0 commit comments