diff --git a/src/Adapter/MSTest.TestAdapter/DynamicDataOperations.cs b/src/Adapter/MSTest.TestAdapter/DynamicDataOperations.cs index c33c1f1b7d..68775df2ab 100644 --- a/src/Adapter/MSTest.TestAdapter/DynamicDataOperations.cs +++ b/src/Adapter/MSTest.TestAdapter/DynamicDataOperations.cs @@ -203,7 +203,7 @@ private static bool TryHandleTupleDataSource(object data, List objects #else Type type = data.GetType(); if (IsTupleOrValueTuple(data.GetType(), out int tupleSize) - && (objects.Count == 0 || objects[objects.Count - 1].Length == tupleSize)) + && (objects.Count == 0 || objects[^1].Length == tupleSize)) { object[] array = new object[tupleSize]; for (int i = 0; i < tupleSize; i++) diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs b/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs index 7fb4dd3131..9b925163bb 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs @@ -721,9 +721,7 @@ void DoRun() { if (results.Length > 0) { -#pragma warning disable IDE0056 // Use index operator - UnitTestResult lastResult = results[results.Length - 1]; -#pragma warning restore IDE0056 // Use index operator + UnitTestResult lastResult = results[^1]; lastResult.Outcome = ObjectModelUnitTestOutcome.Error; lastResult.ErrorMessage = ex.Message; lastResult.ErrorStackTrace = ex.StackTrace; @@ -733,9 +731,7 @@ void DoRun() { if (results.Length > 0) { -#pragma warning disable IDE0056 // Use index operator - UnitTestResult lastResult = results[results.Length - 1]; -#pragma warning restore IDE0056 // Use index operator + UnitTestResult lastResult = results[^1]; lastResult.StandardOut += initializationLogs; lastResult.StandardError += initializationErrorLogs; lastResult.DebugTrace += initializationTrace; diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs b/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs index 017f45b100..f7014db3ed 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs @@ -130,16 +130,14 @@ UnitTestResult[] SafeRunTestMethod(string initializationLogs, string initializat result = [new()]; } -#pragma warning disable IDE0056 // Use index operator - result[result.Length - 1] = new UnitTestResult(new TestFailedException(UnitTestOutcome.Error, ex.TryGetMessage(), ex.TryGetStackTraceInformation())) + result[^1] = new UnitTestResult(new TestFailedException(UnitTestOutcome.Error, ex.TryGetMessage(), ex.TryGetStackTraceInformation())) { - StandardOut = result[result.Length - 1].StandardOut, - StandardError = result[result.Length - 1].StandardError, - DebugTrace = result[result.Length - 1].DebugTrace, - TestContextMessages = result[result.Length - 1].TestContextMessages, - Duration = result[result.Length - 1].Duration, + StandardOut = result[^1].StandardOut, + StandardError = result[^1].StandardError, + DebugTrace = result[^1].DebugTrace, + TestContextMessages = result[^1].TestContextMessages, + Duration = result[^1].Duration, }; -#pragma warning restore IDE0056 // Use index operator } finally { diff --git a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs index 8f706dd7a8..64cfeb287e 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs @@ -281,9 +281,7 @@ private static void RunAssemblyCleanupIfNeeded(ITestContext testContext, ClassCl { if (results.Length > 0) { -#pragma warning disable IDE0056 // Use index operator - UnitTestResult lastResult = results[results.Length - 1]; -#pragma warning restore IDE0056 // Use index operator + UnitTestResult lastResult = results[^1]; lastResult.Outcome = UnitTestOutcome.Error; lastResult.ErrorMessage = ex.Message; lastResult.ErrorStackTrace = ex.StackTrace; @@ -293,9 +291,7 @@ private static void RunAssemblyCleanupIfNeeded(ITestContext testContext, ClassCl { if (results.Length > 0) { -#pragma warning disable IDE0056 // Use index operator - UnitTestResult lastResult = results[results.Length - 1]; -#pragma warning restore IDE0056 // Use index operator + UnitTestResult lastResult = results[^1]; lastResult.StandardOut += initializationLogs; lastResult.StandardError += initializationErrorLogs; lastResult.DebugTrace += initializationTrace; diff --git a/src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/ArrayBuilder.cs b/src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/ArrayBuilder.cs index 81c3fb5952..65092a8b7f 100644 --- a/src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/ArrayBuilder.cs +++ b/src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/ArrayBuilder.cs @@ -152,10 +152,7 @@ public void Sort(Comparison compare) public void CopyTo(T[] array, int start) => _builder.CopyTo(array, start); - public T Last() => -#pragma warning disable IDE0056 - _builder[_builder.Count - 1]; -#pragma warning restore IDE0056 + public T Last() => _builder[^1]; public T First() => _builder[0];