diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Errors.cs b/src/libraries/Common/src/Interop/Unix/Interop.Errors.cs index 49cc830e00e82..dad796280e71a 100644 --- a/src/libraries/Common/src/Interop/Unix/Interop.Errors.cs +++ b/src/libraries/Common/src/Interop/Unix/Interop.Errors.cs @@ -115,7 +115,7 @@ internal enum Error // Represents a platform-agnostic Error and underlying platform-specific errno internal struct ErrorInfo { - private Error _error; + private readonly Error _error; private int _rawErrno; internal ErrorInfo(int errno) diff --git a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs index 764bdaf85afee..0b9e2c283f0f8 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs @@ -5,7 +5,6 @@ using System; using System.Globalization; using System.Runtime.InteropServices; -using System.Text; internal static partial class Interop { diff --git a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Casing.cs b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Casing.cs index 503a864d693c6..499f9445d89ce 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Casing.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Casing.cs @@ -2,10 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; -using System.Security; -using System.Text; internal static partial class Interop { diff --git a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Collation.cs b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Collation.cs index 7d0175473d794..a59292e0fca1d 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Collation.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Collation.cs @@ -5,7 +5,6 @@ using System; using System.Globalization; using System.Runtime.InteropServices; -using System.Security; internal static partial class Interop { diff --git a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.ICU.cs b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.ICU.cs index f24c2607848b9..0dce072958a7f 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.ICU.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.ICU.cs @@ -2,9 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; -using System.Runtime.CompilerServices; internal static partial class Interop { diff --git a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Idna.cs b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Idna.cs index 89b6c3cebec0a..e9014da1e5d9e 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Idna.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Idna.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Locale.cs b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Locale.cs index d9a300fd156dc..a6517185ce063 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Locale.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Locale.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs index d442da0ea137f..09307d22545f6 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; using System.Text; diff --git a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs index df488b6ffa1c4..f60b81f0da8cf 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Runtime.InteropServices; -using System.Text; internal static partial class Interop { diff --git a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Utils.cs b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Utils.cs index 627ab56c9187c..11534cbdee756 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Utils.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Globalization.Native/Interop.Utils.cs @@ -3,9 +3,7 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Buffers; -using System.Text; internal static partial class Interop { diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Access.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Access.cs index a723f572a5b0a..b9750fa108330 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Access.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Access.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.ChDir.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.ChDir.cs index 3c66995182aca..8979d10f4cd8c 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.ChDir.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.ChDir.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs index a630a3e82c34a..509fef8272df2 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetEUid.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetEUid.cs index 8b525fa327294..c964dec144e1b 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetEUid.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetEUid.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPid.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPid.cs index 02d259db7d18c..b93f0895360e0 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPid.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPid.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPwUid.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPwUid.cs index 28b2309d03ec9..5a9a23f87e06f 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPwUid.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPwUid.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetRandomBytes.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetRandomBytes.cs index 858506935aef3..fcc9b8db944a5 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetRandomBytes.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetRandomBytes.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Diagnostics; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.LockFileRegion.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.LockFileRegion.cs index 1deb9a4313208..5f92357e8f81e 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.LockFileRegion.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.LockFileRegion.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs index 134dcb920375f..21479bca65cc9 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.PathConf.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.PathConf.cs index 7213cb02640ff..e2c127772020b 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.PathConf.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.PathConf.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Read.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Read.cs index 233feabdbb695..e37a2ae6c1d7e 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Read.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Read.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; internal static partial class Interop { diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Write.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Write.cs index fb06d463beb76..c80f1041fd962 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Write.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Write.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; internal static partial class Interop { diff --git a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs index ad9e3eaba0c52..4a3b2cee46560 100644 --- a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs @@ -5,7 +5,6 @@ using System; using System.Diagnostics; using System.IO; -using System.Runtime.InteropServices; namespace Microsoft.Win32.SafeHandles { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ISet.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ISet.cs index 657adf787afa4..ce71acba6258b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ISet.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ISet.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.CompilerServices; - namespace System.Collections.Generic { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/DebugProvider.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/DebugProvider.Unix.cs index 9259c4fbe66ce..55dcaffa0ea3b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/DebugProvider.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/DebugProvider.Unix.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Win32.SafeHandles; - namespace System.Diagnostics { public partial class DebugProvider diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs index 88c1434b0cce3..308c19ada6281 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. + using System.Collections.Generic; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSourceHelper.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSourceHelper.Unix.cs index da952d12b4c8a..7b6e43f9ffb4f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSourceHelper.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSourceHelper.Unix.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; - namespace System.Diagnostics.Tracing { internal static class RuntimeEventSourceHelper diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.NoRegistry.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.NoRegistry.cs index 6e699b1f38616..06e35e387f22a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.NoRegistry.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.NoRegistry.cs @@ -2,9 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; using System.Collections; -using Microsoft.Win32; namespace System { diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs index 8e7982e9992be..993b23a89fc68 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Unix.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; @@ -454,8 +452,8 @@ public static long WorkingSet { using (currentProcess) { - object? result = processType!.GetMethod("get_WorkingSet64")?.Invoke(currentProcess, BindingFlags.DoNotWrapExceptions, null, null, null); - if (result is long) return (long)result; + if (processType!.GetMethod("get_WorkingSet64")?.Invoke(currentProcess, BindingFlags.DoNotWrapExceptions, null, null, null) is long result) + return result; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs index d8ed0072f3779..e62a707684cc0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Diagnostics; -using System.Security; using System.Text; using Internal.Runtime.CompilerServices; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Unix.cs index a8eb8dfdeb00e..4158890e959e4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Unix.cs @@ -5,12 +5,7 @@ using System.Buffers; using System.Collections.Generic; using System.Diagnostics; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Security; -using System.Threading; - -using Internal.Runtime.CompilerServices; namespace System.Globalization { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs index f3c3e5d4a329f..67ad489e47adf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs @@ -2,12 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Generic; using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security; -using System.Text; namespace System.Globalization { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Unix.cs index 0bbebba774284..ed4e20de10447 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Unix.cs @@ -74,7 +74,7 @@ private static bool GetJapaneseEraStartDate(int era, out DateTime dateTime) { Debug.Assert(!GlobalizationMode.Invariant); - dateTime = default(DateTime); + dateTime = default; int startYear; int startMonth; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.Unix.cs index 02e7c5f50b969..ef6cff420b9d2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.Unix.cs @@ -3,9 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security; -using System.Text; namespace System.Globalization { diff --git a/src/libraries/System.Private.CoreLib/src/System/Guid.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Guid.Unix.cs index 5a1364d032d2e..3ee426d23a401 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Guid.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Guid.Unix.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; -using System.Runtime.InteropServices; - namespace System { public partial struct Guid diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/BufferedStream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/BufferedStream.cs index 61acd65b589d8..6ab6272fed463 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/BufferedStream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/BufferedStream.cs @@ -672,7 +672,7 @@ public override Task ReadAsync(byte[] buffer, int offset, int count, Cancel cancellationToken, bytesFromBuffer, semaphoreLockTask).AsTask(); } - public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) { if (cancellationToken.IsCancellationRequested) { @@ -837,19 +837,6 @@ private int WriteToBuffer(ReadOnlySpan buffer) return bytesToWrite; } - private void WriteToBuffer(byte[] array, ref int offset, ref int count, out Exception? error) - { - try - { - error = null; - WriteToBuffer(array, ref offset, ref count); - } - catch (Exception ex) - { - error = ex; - } - } - public override void Write(byte[] array, int offset, int count) { if (array == null) @@ -1074,7 +1061,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati return WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken).AsTask(); } - public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) { // Fast path check for cancellation already requested if (cancellationToken.IsCancellationRequested) diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/DriveInfoInternal.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/DriveInfoInternal.Unix.cs index 78ef95704fe9b..20e2cf9b9ab41 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/DriveInfoInternal.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/DriveInfoInternal.Unix.cs @@ -2,9 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; -using System.Text; - namespace System.IO { /// Contains internal volume helpers that are shared between many projects. diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileAttributes.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileAttributes.cs index 90351282f6ce5..5f53a5d99579a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileAttributes.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileAttributes.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; - namespace System.IO { [Flags] diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Linux.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Linux.cs index 873c4eb5599d8..6cc56e6acf00e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Linux.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Linux.cs @@ -2,11 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Win32.SafeHandles; -using System.Diagnostics; -using System.Threading; -using System.Threading.Tasks; - namespace System.IO { public partial class FileStream : Stream diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs index 2a8e277c35e63..855397ce0dc2e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs @@ -143,7 +143,7 @@ private void InitFromHandle(SafeFileHandle handle, FileAccess access, bool useAs private static Interop.Sys.OpenFlags PreOpenConfigurationFromOptions(FileMode mode, FileAccess access, FileShare share, FileOptions options) { // Translate FileMode. Most of the values map cleanly to one or more options for open. - Interop.Sys.OpenFlags flags = default(Interop.Sys.OpenFlags); + Interop.Sys.OpenFlags flags = default; switch (mode) { default: @@ -574,7 +574,7 @@ private unsafe int ReadNative(Span buffer) try { Memory memory = thisRef._asyncState.Memory; - thisRef._asyncState.Memory = default(Memory); + thisRef._asyncState.Memory = default; return thisRef.ReadSpan(memory.Span); } finally { thisRef._asyncState.Release(); } @@ -733,7 +733,7 @@ private ValueTask WriteAsyncInternal(ReadOnlyMemory source, CancellationTo try { ReadOnlyMemory readOnlyMemory = thisRef._asyncState.ReadOnlyMemory; - thisRef._asyncState.ReadOnlyMemory = default(ReadOnlyMemory); + thisRef._asyncState.ReadOnlyMemory = default; thisRef.WriteSpan(readOnlyMemory.Span); } finally { thisRef._asyncState.Release(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs index 288cc12ec8237..23c35de1d521f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs @@ -4,7 +4,6 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; using System.Text; namespace System.IO diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.Unix.cs index 4d652b6417f59..77dab304e1566 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.Unix.cs @@ -5,7 +5,6 @@ #nullable enable using System.Diagnostics; using System.Text; -using System.Runtime.InteropServices; using System.Diagnostics.CodeAnalysis; namespace System.IO diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs index e5cd43201d462..c49c02c18dd20 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs @@ -899,7 +899,7 @@ public static Matrix4x4 CreatePerspectiveFieldOfView(float fieldOfView, float as result.M21 = result.M23 = result.M24 = 0.0f; result.M31 = result.M32 = 0.0f; - var negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance); + float negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance); result.M33 = negFarRange; result.M34 = -1.0f; @@ -936,7 +936,7 @@ public static Matrix4x4 CreatePerspective(float width, float height, float nearP result.M22 = 2.0f * nearPlaneDistance / height; result.M21 = result.M23 = result.M24 = 0.0f; - var negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance); + float negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance); result.M33 = negFarRange; result.M31 = result.M32 = 0.0f; result.M34 = -1.0f; @@ -978,7 +978,7 @@ public static Matrix4x4 CreatePerspectiveOffCenter(float left, float right, floa result.M31 = (left + right) / (right - left); result.M32 = (top + bottom) / (top - bottom); - var negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance); + float negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance); result.M33 = negFarRange; result.M34 = -1.0f; @@ -1761,15 +1761,15 @@ public static unsafe Matrix4x4 Transpose(Matrix4x4 matrix) { if (Sse.IsSupported) { - var row1 = Sse.LoadVector128(&matrix.M11); - var row2 = Sse.LoadVector128(&matrix.M21); - var row3 = Sse.LoadVector128(&matrix.M31); - var row4 = Sse.LoadVector128(&matrix.M41); + Vector128 row1 = Sse.LoadVector128(&matrix.M11); + Vector128 row2 = Sse.LoadVector128(&matrix.M21); + Vector128 row3 = Sse.LoadVector128(&matrix.M31); + Vector128 row4 = Sse.LoadVector128(&matrix.M41); - var l12 = Sse.UnpackLow(row1, row2); - var l34 = Sse.UnpackLow(row3, row4); - var h12 = Sse.UnpackHigh(row1, row2); - var h34 = Sse.UnpackHigh(row3, row4); + Vector128 l12 = Sse.UnpackLow(row1, row2); + Vector128 l34 = Sse.UnpackLow(row3, row4); + Vector128 h12 = Sse.UnpackHigh(row1, row2); + Vector128 h34 = Sse.UnpackHigh(row3, row4); Sse.Store(&matrix.M11, Sse.MoveLowToHigh(l12, l34)); Sse.Store(&matrix.M21, Sse.MoveHighToLow(l34, l12)); @@ -2016,7 +2016,7 @@ public static unsafe Matrix4x4 Lerp(Matrix4x4 matrix1, Matrix4x4 matrix2, float { if (Sse.IsSupported) { - var row = Sse.LoadVector128(&value1.M11); + Vector128 row = Sse.LoadVector128(&value1.M11); Sse.Store(&value1.M11, Sse.Add(Sse.Add(Sse.Multiply(Sse.Shuffle(row, row, 0x00), Sse.LoadVector128(&value2.M11)), Sse.Multiply(Sse.Shuffle(row, row, 0x55), Sse.LoadVector128(&value2.M21))), diff --git a/src/libraries/System.Private.CoreLib/src/System/PasteArguments.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/PasteArguments.Unix.cs index 1a4d92850f890..ccb810a6de860 100644 --- a/src/libraries/System.Private.CoreLib/src/System/PasteArguments.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/PasteArguments.Unix.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using System.Runtime.CompilerServices; using System.Text; namespace System diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs index 7b29d6f9ad0e4..422698ce088ab 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.InteropServices.ComTypes; - namespace System.Runtime.InteropServices { public static class ComEventsHelper diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs index 77e8b35baae46..05764b08bac53 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections; namespace System.Runtime.InteropServices @@ -47,7 +46,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa throw new PlatformNotSupportedException(); } - protected unsafe abstract ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count); + protected abstract unsafe ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count); public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateObjectFlags flags) { @@ -73,4 +72,4 @@ protected static void GetIUnknownImpl(out IntPtr fpQueryInterface, out IntPtr fp throw new PlatformNotSupportedException(); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs index 9629fa4286abb..3795a5b451577 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs @@ -364,7 +364,7 @@ public Assembly LoadFromStream(Stream assembly, Stream? assemblySymbols) byte[]? arrSymbols = null; if (assemblySymbols != null) { - var iSymbolLength = (int)assemblySymbols.Length; + int iSymbolLength = (int)assemblySymbols.Length; arrSymbols = new byte[iSymbolLength]; assemblySymbols.Read(arrSymbols, 0, iSymbolLength); diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/Permissions/CodeAccessSecurityAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Security/Permissions/CodeAccessSecurityAttribute.cs index a816f1d0162a2..1a27b3b39da68 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/Permissions/CodeAccessSecurityAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/Permissions/CodeAccessSecurityAttribute.cs @@ -7,6 +7,6 @@ namespace System.Security.Permissions [AttributeUsage((AttributeTargets)(109), AllowMultiple = true, Inherited = false)] public abstract partial class CodeAccessSecurityAttribute : SecurityAttribute { - protected CodeAccessSecurityAttribute(SecurityAction action) : base(default(SecurityAction)) { } + protected CodeAccessSecurityAttribute(SecurityAction action) : base(default) { } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/Permissions/SecurityPermissionAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Security/Permissions/SecurityPermissionAttribute.cs index e1e74c4166a00..2ec3057bb91a7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/Permissions/SecurityPermissionAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/Permissions/SecurityPermissionAttribute.cs @@ -7,7 +7,7 @@ namespace System.Security.Permissions [AttributeUsage((AttributeTargets)(109), AllowMultiple = true, Inherited = false)] public sealed partial class SecurityPermissionAttribute : CodeAccessSecurityAttribute { - public SecurityPermissionAttribute(SecurityAction action) : base(default(SecurityAction)) { } + public SecurityPermissionAttribute(SecurityAction action) : base(default) { } public bool Assertion { get; set; } public bool BindingRedirects { get; set; } public bool ControlAppDomain { get; set; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/Principal/TokenImpersonationLevel.cs b/src/libraries/System.Private.CoreLib/src/System/Security/Principal/TokenImpersonationLevel.cs index 406342ba268cc..25b0e977e1143 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/Principal/TokenImpersonationLevel.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/Principal/TokenImpersonationLevel.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; - namespace System.Security.Principal { public enum TokenImpersonationLevel diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.Unix.cs index d3fbd9b2bddc9..ca17a89876c42 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.Unix.cs @@ -2,11 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; -using System.Runtime; -using System.Runtime.InteropServices; -using System.Text; - namespace System.Security { // SecureString attempts to provide a defense-in-depth solution. diff --git a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs index 978f3cebb61ad..0b354c3b89d35 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Runtime.CompilerServices; using Internal.Runtime.CompilerServices; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs index 8d23f74cfe89b..73bfa603f9252 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs @@ -3,9 +3,9 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -using System.Runtime.CompilerServices; using System.Numerics; #if SYSTEM_PRIVATE_CORELIB diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs index a1288394d7045..64f76fec69147 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Buffers; -using System.Buffers.Binary; using System.Diagnostics; using System.Numerics; using System.Runtime.CompilerServices; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Validation.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Validation.cs index 137b6775c8944..2d250e7d0ce71 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Validation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Validation.cs @@ -4,8 +4,8 @@ using System.Diagnostics; using System.Numerics; -using System.Runtime.Intrinsics.X86; using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics.X86; #if SYSTEM_PRIVATE_CORELIB using Internal.Runtime.CompilerServices; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.WhiteSpace.CoreLib.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.WhiteSpace.CoreLib.cs index 373f764efd7d0..cf656bc1dc2d1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.WhiteSpace.CoreLib.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.WhiteSpace.CoreLib.cs @@ -7,7 +7,6 @@ #pragma warning disable SA1121 // explicitly using type aliases instead of built-in types #if TARGET_64BIT -using nint = System.Int64; using nuint = System.UInt64; #else using nint = System.Int32; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Windows.cs index 286ec0310d2ad..fe0c5adecd163 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Windows.cs @@ -27,7 +27,7 @@ private void Create(int maximumSignalCount) Interop.Kernel32.CreateIoCompletionPort(new IntPtr(-1), IntPtr.Zero, UIntPtr.Zero, maximumSignalCount); if (_completionPort == IntPtr.Zero) { - var error = Marshal.GetLastWin32Error(); + int error = Marshal.GetLastWin32Error(); var exception = new OutOfMemoryException(); exception.HResult = error; throw exception; @@ -46,7 +46,7 @@ public bool WaitCore(int timeoutMs) { Debug.Assert(timeoutMs >= -1); - bool success = Interop.Kernel32.GetQueuedCompletionStatus(_completionPort, out var numberOfBytes, out var completionKey, out var pointerToOverlapped, timeoutMs); + bool success = Interop.Kernel32.GetQueuedCompletionStatus(_completionPort, out int numberOfBytes, out UIntPtr completionKey, out IntPtr pointerToOverlapped, timeoutMs); Debug.Assert(success || (Marshal.GetLastWin32Error() == WaitHandle.WaitTimeout)); return success; } @@ -59,7 +59,7 @@ public void ReleaseCore(int count) { if (!Interop.Kernel32.PostQueuedCompletionStatus(_completionPort, 1, UIntPtr.Zero, IntPtr.Zero)) { - var lastError = Marshal.GetLastWin32Error(); + int lastError = Marshal.GetLastWin32Error(); var exception = new OutOfMemoryException(); exception.HResult = lastError; throw exception; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs index 62affa80c3075..3cf328d2a40ae 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs @@ -15,8 +15,8 @@ internal sealed partial class LowLevelLifoSemaphore : IDisposable { private CacheLineSeparatedCounts _separated; - private int _maximumSignalCount; - private int _spinCount; + private readonly int _maximumSignalCount; + private readonly int _spinCount; private const int SpinSleep0Threshold = 10; @@ -287,9 +287,9 @@ public override int GetHashCode() [StructLayout(LayoutKind.Sequential)] private struct CacheLineSeparatedCounts { - private Internal.PaddingFor32 _pad1; + private readonly Internal.PaddingFor32 _pad1; public Counts _counts; - private Internal.PaddingFor32 _pad2; + private readonly Internal.PaddingFor32 _pad2; } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.CpuUtilizationReader.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.CpuUtilizationReader.Windows.cs index ee78997955279..50c841fe9503a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.CpuUtilizationReader.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.CpuUtilizationReader.Windows.cs @@ -19,7 +19,7 @@ public int CurrentUtilization { get { - if (!Interop.Kernel32.GetSystemTimes(out var idleTime, out var kernelTime, out var userTime)) + if (!Interop.Kernel32.GetSystemTimes(out long idleTime, out long kernelTime, out long userTime)) { return 0; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs index b1eae812b4c80..0fa48e9d870fd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.HillClimbing.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Globalization; namespace System.Threading { @@ -83,13 +82,13 @@ private struct LogEntry private double _completionsSinceLastChange; private int _accumulatedCompletionCount; private double _accumulatedSampleDurationSeconds; - private double[] _samples; - private double[] _threadCounts; + private readonly double[] _samples; + private readonly double[] _threadCounts; private int _currentSampleMs; - private Random _randomIntervalGenerator = new Random(); + private readonly Random _randomIntervalGenerator = new Random(); - private LogEntry[] _log = new LogEntry[LogCapacity]; + private readonly LogEntry[] _log = new LogEntry[LogCapacity]; private int _logStart = 0; private int _logSize = 0; @@ -197,10 +196,10 @@ private struct LogEntry // // Set up defaults for our metrics // - Complex threadWaveComponent = default(Complex); - Complex throughputWaveComponent = default(Complex); + Complex threadWaveComponent = default; + Complex throughputWaveComponent = default; double throughputErrorEstimate = 0; - Complex ratio = default(Complex); + Complex ratio = default; double confidence = 0; StateOrTransition state = StateOrTransition.Warmup; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs index 593429973b0f2..e30253f900b75 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Runtime.InteropServices; namespace System.Threading { @@ -13,9 +12,8 @@ internal partial class PortableThreadPool /// A linked list of s. /// private WaitThreadNode _waitThreadsHead; - private WaitThreadNode _waitThreadsTail; - private LowLevelLock _waitThreadLock = new LowLevelLock(); + private readonly LowLevelLock _waitThreadLock = new LowLevelLock(); /// /// Register a wait handle on a . @@ -28,7 +26,7 @@ internal void RegisterWaitHandle(RegisteredWaitHandle handle) { if (_waitThreadsHead == null) // Lazily create the first wait thread. { - _waitThreadsTail = _waitThreadsHead = new WaitThreadNode + _waitThreadsHead = new WaitThreadNode { Thread = new WaitThread() }; @@ -48,7 +46,7 @@ internal void RegisterWaitHandle(RegisteredWaitHandle handle) } while (current != null); // If all wait threads are full, create a new one. - prev.Next = _waitThreadsTail = new WaitThreadNode + prev.Next = new WaitThreadNode { Thread = new WaitThread() }; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs index 3fdf1f65767af..b120265a05336 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Globalization; - namespace System.Threading { internal partial class PortableThreadPool @@ -16,7 +14,7 @@ private static class WorkerThread /// /// Semaphore for controlling how many threads are currently working. /// - private static LowLevelLifoSemaphore s_semaphore = new LowLevelLifoSemaphore(0, MaxPossibleThreadCount, SemaphoreSpinCount); + private static readonly LowLevelLifoSemaphore s_semaphore = new LowLevelLifoSemaphore(0, MaxPossibleThreadCount, SemaphoreSpinCount); /// /// Maximum number of spins a thread pool worker thread performs before waiting for work diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs index 3529148f53437..25f4349386772 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs @@ -62,7 +62,7 @@ private struct CacheLineSeparated private readonly ThreadInt64PersistentCounter _completionCounter = new ThreadInt64PersistentCounter(); private int _threadAdjustmentIntervalMs; - private LowLevelLock _hillClimbingThreadAdjustmentLock = new LowLevelLock(); + private readonly LowLevelLock _hillClimbingThreadAdjustmentLock = new LowLevelLock(); private volatile int _numRequestedWorkers = 0; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.Unix.cs index 902fcf2650e1d..35379f1f10283 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.Unix.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.ConstrainedExecution; - namespace System.Threading { public sealed partial class Thread diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs index 85c9e0033e718..f56414a8a7ab1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; namespace System.Threading @@ -104,7 +103,7 @@ internal void RestartTimeout(int currentTimeMs) /// private int _numRequestedCallbacks; - private LowLevelLock _callbackLock = new LowLevelLock(); + private readonly LowLevelLock _callbackLock = new LowLevelLock(); /// /// Notes if we need to signal the user's unregister event after all callbacks complete. diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolBoundHandle.PlatformNotSupported.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolBoundHandle.PlatformNotSupported.cs index e97b1e9e82b3a..2442d71c4170a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolBoundHandle.PlatformNotSupported.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolBoundHandle.PlatformNotSupported.cs @@ -2,11 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Win32.SafeHandles; -using System.Diagnostics; using System.Runtime.InteropServices; -using System.Threading; -using System.IO; namespace System.Threading { diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs index 92d3130a6c764..ec137cdd87a1a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs @@ -11,8 +11,6 @@ using System.Text; using System.Threading; using System.Security; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using Internal.IO; @@ -175,20 +173,20 @@ public AdjustmentRule[] GetAdjustmentRules() for (int i = 0; i < _adjustmentRules.Length; i++) { - var rule = _adjustmentRules[i]; - var start = rule.DateStart.Kind == DateTimeKind.Utc ? + AdjustmentRule? rule = _adjustmentRules[i]; + DateTime start = rule.DateStart.Kind == DateTimeKind.Utc ? // At the daylight start we didn't start the daylight saving yet then we convert to Local time // by adding the _baseUtcOffset to the UTC time new DateTime(rule.DateStart.Ticks + _baseUtcOffset.Ticks, DateTimeKind.Unspecified) : rule.DateStart; - var end = rule.DateEnd.Kind == DateTimeKind.Utc ? + DateTime end = rule.DateEnd.Kind == DateTimeKind.Utc ? // At the daylight saving end, the UTC time is mapped to local time which is already shifted by the daylight delta // we calculate the local time by adding _baseUtcOffset + DaylightDelta to the UTC time new DateTime(rule.DateEnd.Ticks + _baseUtcOffset.Ticks + rule.DaylightDelta.Ticks, DateTimeKind.Unspecified) : rule.DateEnd; - var startTransition = TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, start.Hour, start.Minute, start.Second), start.Month, start.Day); - var endTransition = TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, end.Hour, end.Minute, end.Second), end.Month, end.Day); + TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, start.Hour, start.Minute, start.Second), start.Month, start.Day); + TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, end.Hour, end.Minute, end.Second), end.Month, end.Day); rules[i] = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(start.Date, end.Date, rule.DaylightDelta, startTransition, endTransition); } @@ -938,8 +936,8 @@ internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool DateTime.MinValue, endTransitionDate.AddTicks(-1), daylightDelta, - default(TransitionTime), - default(TransitionTime), + default, + default, baseUtcDelta, noDaylightTransitions: true); @@ -974,7 +972,7 @@ internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool } else { - dstStart = default(TransitionTime); + dstStart = default; } AdjustmentRule r = AdjustmentRule.CreateAdjustmentRule( @@ -982,7 +980,7 @@ internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool endTransitionDate.AddTicks(-1), daylightDelta, dstStart, - default(TransitionTime), + default, baseUtcDelta, noDaylightTransitions: true); @@ -1144,8 +1142,8 @@ private static TZifType TZif_GetEarlyDateTransitionType(TZifType[] transitionTyp startTransitionDate, DateTime.MaxValue, TimeSpan.Zero, - default(TransitionTime), - default(TransitionTime), + default, + default, baseOffset, noDaylightTransitions: true); } @@ -1359,7 +1357,7 @@ private static bool TZif_ParseMDateRule(ReadOnlySpan dateRule, out int mon month = 0; week = 0; - dayOfWeek = default(DayOfWeek); + dayOfWeek = default; return false; } diff --git a/src/mono/netcore/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.Unix.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.Unix.Mono.cs index 007b126965790..5a0247cd4635d 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.Unix.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.Unix.Mono.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Threading; using System.Runtime.CompilerServices; namespace Microsoft.Win32.SafeHandles diff --git a/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoDomain.cs b/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoDomain.cs index e74ce9fbe0ef5..ca4d98404c986 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoDomain.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoDomain.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Reflection; using System.Runtime.InteropServices; namespace Mono diff --git a/src/mono/netcore/System.Private.CoreLib/src/Mono/RuntimeHandles.cs b/src/mono/netcore/System.Private.CoreLib/src/Mono/RuntimeHandles.cs index 1d05876ce99a3..7e2afa4972840 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/Mono/RuntimeHandles.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/Mono/RuntimeHandles.cs @@ -10,7 +10,7 @@ namespace Mono { internal unsafe struct RuntimeClassHandle { - private RuntimeStructs.MonoClass* value; + private readonly RuntimeStructs.MonoClass* value; internal RuntimeClassHandle(RuntimeStructs.MonoClass* value) { @@ -60,14 +60,14 @@ public bool Equals(RuntimeClassHandle handle) } [MethodImpl(MethodImplOptions.InternalCall)] - internal static unsafe extern IntPtr GetTypeFromClass(RuntimeStructs.MonoClass* klass); + internal static extern unsafe IntPtr GetTypeFromClass(RuntimeStructs.MonoClass* klass); internal RuntimeTypeHandle GetTypeHandle() => new RuntimeTypeHandle(GetTypeFromClass(value)); } internal unsafe struct RuntimeRemoteClassHandle { - private RuntimeStructs.RemoteClass* value; + private readonly RuntimeStructs.RemoteClass* value; internal RuntimeRemoteClassHandle(RuntimeStructs.RemoteClass* value) { @@ -85,7 +85,7 @@ internal RuntimeClassHandle ProxyClass internal unsafe struct RuntimeGenericParamInfoHandle { - private RuntimeStructs.GenericParamInfo* value; + private readonly RuntimeStructs.GenericParamInfo* value; internal RuntimeGenericParamInfoHandle(RuntimeStructs.GenericParamInfo* value) { @@ -128,7 +128,7 @@ private int GetConstraintsCount() internal struct RuntimeEventHandle { - private IntPtr value; + private readonly IntPtr value; internal RuntimeEventHandle(IntPtr v) { @@ -168,7 +168,7 @@ public override int GetHashCode() internal struct RuntimePropertyHandle { - private IntPtr value; + private readonly IntPtr value; internal RuntimePropertyHandle(IntPtr v) { diff --git a/src/mono/netcore/System.Private.CoreLib/src/Mono/SafeGPtrArrayHandle.cs b/src/mono/netcore/System.Private.CoreLib/src/Mono/SafeGPtrArrayHandle.cs index 2f8a550049284..a0c394dab8568 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/Mono/SafeGPtrArrayHandle.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/Mono/SafeGPtrArrayHandle.cs @@ -10,7 +10,6 @@ // using System; -using System.Runtime.CompilerServices; namespace Mono { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs index bfbed4dd48925..f6c23ac0cbe69 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs @@ -3,12 +3,10 @@ // See the LICENSE file in the project root for more information. using Internal.Runtime.CompilerServices; -using System.Collections; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using Mono; #pragma warning disable SA1121 // explicitly using type aliases instead of built-in types #if TARGET_64BIT @@ -143,7 +141,7 @@ private static void Copy(Array sourceArray, int sourceIndex, Array destinationAr Type src_type = sourceArray.GetType().GetElementType()!; Type dst_type = destinationArray.GetType().GetElementType()!; - var dst_type_vt = dst_type.IsValueType && Nullable.GetUnderlyingType(dst_type) == null; + bool dst_type_vt = dst_type.IsValueType && Nullable.GetUnderlyingType(dst_type) == null; bool src_is_enum = src_type.IsEnum; bool dst_is_enum = dst_type.IsEnum; @@ -381,7 +379,7 @@ public object GetValue(int index) if (Rank != 1) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need1DArray); - var lb = GetLowerBound(0); + int lb = GetLowerBound(0); if (index < lb || index > GetUpperBound(0)) throw new IndexOutOfRangeException("Index has to be between upper and lower bound of the array."); @@ -428,7 +426,7 @@ public void SetValue(object? value, int index) if (Rank != 1) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need1DArray); - var lb = GetLowerBound(0); + int lb = GetLowerBound(0); if (index < lb || index > GetUpperBound(0)) throw new IndexOutOfRangeException("Index has to be >= lower bound and <= upper bound of the array."); @@ -524,14 +522,14 @@ public int GetUpperBound(int dimension) [Intrinsic] private void GetGenericValueImpl(int pos, out T value) { - var self = this; + Array self = this; GetGenericValue_icall(ref self, pos, out value); } [Intrinsic] private void SetGenericValueImpl(int pos, ref T value) { - var self = this; + Array self = this; SetGenericValue_icall(ref self, pos, ref value); } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Attribute.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Attribute.Mono.cs index 4fe6b1181ac10..bf2177509d96c 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Attribute.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Attribute.Mono.cs @@ -16,7 +16,7 @@ public partial class Attribute if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute) && attributeType != typeof(CustomAttribute)) throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName); - var attrs = CustomAttribute.GetCustomAttributes(element, attributeType, inherit); + object[] attrs = CustomAttribute.GetCustomAttributes(element, attributeType, inherit); if (attrs == null || attrs.Length == 0) return null; if (attrs.Length != 1) diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs index 13500a5594d99..596c2c77ca8d3 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs @@ -32,7 +32,6 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Runtime.Serialization; namespace System { @@ -436,7 +435,7 @@ private static bool IsArgumentTypeMatchWithThis(Type delArgType, Type argType, b #nullable restore } - var target = _target; + object? target = _target; if (data is null) data = CreateDelegateData(); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/StackFrame.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/StackFrame.Mono.cs index 74e401f1a943b..48e7376c046c7 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/StackFrame.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/StackFrame.Mono.cs @@ -31,7 +31,7 @@ private void BuildStackFrame(int skipFrames, bool needFileInfo) { const int SystemDiagnosticsStackDepth = 3; - if (skipFrames + SystemDiagnosticsStackDepth < 0 || !get_frame_info(skipFrames + SystemDiagnosticsStackDepth, needFileInfo, out var method, out var ilOffset, out var nativeOffset, out var fileName, out var line, out var column)) + if (skipFrames + SystemDiagnosticsStackDepth < 0 || !get_frame_info(skipFrames + SystemDiagnosticsStackDepth, needFileInfo, out MethodBase? method, out int ilOffset, out int nativeOffset, out string? fileName, out int line, out int column)) return; _method = method; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/StackTrace.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/StackTrace.Mono.cs index 79e8b48270de4..6b9be66ec6cf6 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/StackTrace.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/StackTrace.Mono.cs @@ -60,7 +60,7 @@ private void InitializeForCurrentThread(int skipFrames, bool needFileInfo) private void InitializeForException(Exception e, int skipFrames, bool needFileInfo) { - var frames = get_trace(e, skipFrames, needFileInfo); + MonoStackFrame[] frames = get_trace(e, skipFrames, needFileInfo); _numOfFrames = frames.Length; int foreignFrames; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.Mono.cs index de832fa5d0447..1d1d02fb042ba 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.Mono.cs @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. + using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; #if FEATURE_PERFTRACING @@ -13,7 +13,7 @@ internal static partial class EventPipeInternal // These ICalls are used by the configuration APIs to interact with EventPipe. // [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static unsafe extern ulong Enable(char* outputFile, EventPipeSerializationFormat format, uint circularBufferSizeInMB, EventPipeProviderConfigurationNative* providers, uint numProviders); + private static extern unsafe ulong Enable(char* outputFile, EventPipeSerializationFormat format, uint circularBufferSizeInMB, EventPipeProviderConfigurationNative* providers, uint numProviders); [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void Disable(ulong sessionID); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Enum.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Enum.Mono.cs index 88bb891eb2662..0c7da0c2ccc68 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Enum.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Enum.Mono.cs @@ -95,11 +95,11 @@ internal static string[] InternalGetNames(RuntimeType enumType) private static EnumInfo GetEnumInfo(RuntimeType enumType, bool getNames = true) { - var entry = enumType.Cache.EnumInfo; + EnumInfo? entry = enumType.Cache.EnumInfo; if (entry == null || (getNames && entry.Names == null)) { - if (!GetEnumValuesAndNames(enumType, out var values, out var names)) + if (!GetEnumValuesAndNames(enumType, out ulong[]? values, out string[]? names)) Array.Sort(values, names, Collections.Generic.Comparer.Default); bool hasFlagsAttribute = enumType.IsDefined(typeof(FlagsAttribute), inherit: false); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Environment.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Environment.Mono.cs index 9a18526a9ad6d..86a5b14b8ab6c 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Environment.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Environment.Mono.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections; using System.Globalization; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/GC.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/GC.Mono.cs index dd0a348821261..1276b759bf809 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/GC.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/GC.Mono.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; -using System.Diagnostics; namespace System { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs index 706c3a92a3372..911499ea842e3 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.CompilerServices; namespace System.Globalization { @@ -11,7 +10,7 @@ internal static partial class GlobalizationMode private static bool GetInvariantSwitchValue() { - var val = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); + string? val = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); if (val != null) return bool.IsTrueStringIgnoreCase(val) || val.Equals("1"); return false; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/IO/MonoIOError.cs b/src/mono/netcore/System.Private.CoreLib/src/System/IO/MonoIOError.cs index 6f27c713ddf6e..0bf59a99146bd 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/IO/MonoIOError.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/IO/MonoIOError.cs @@ -30,8 +30,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -using System; - namespace System.IO { internal enum MonoIOError : int diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs b/src/mono/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs index 2ef76dbdbc79f..f3b741f866736 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Reflection; -using System.Runtime.CompilerServices; namespace System { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/mono/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs index 553ee17c1a70f..da9981a4cc43e 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.InteropServices; @@ -212,7 +211,7 @@ protected sealed override Delegate RemoveImpl(Delegate value) } else if (delegates == null) { - foreach (var d in other.delegates) + foreach (Delegate? d in other.delegates) { if (this.Equals(d)) return null; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs index 97ca9ad6e6697..36545f49626cb 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs @@ -82,7 +82,7 @@ public static Assembly Load(AssemblyName assemblyRef) internal static Assembly Load(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext) { // TODO: pass AssemblyName - var assembly = InternalLoad(assemblyRef.FullName, ref stackMark, assemblyLoadContext != null ? assemblyLoadContext.NativeALC : IntPtr.Zero); + Assembly? assembly = InternalLoad(assemblyRef.FullName, ref stackMark, assemblyLoadContext != null ? assemblyLoadContext.NativeALC : IntPtr.Zero); if (assembly == null) throw new FileNotFoundException(null, assemblyRef.Name); return assembly; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/AssemblyName.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/AssemblyName.Mono.cs index 718a1e2436d9e..2291184c4ebf9 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/AssemblyName.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/AssemblyName.Mono.cs @@ -21,10 +21,10 @@ public AssemblyName(string assemblyName) if (assemblyName.Length == 0 || assemblyName[0] == '\0') throw new ArgumentException(SR.Format_StringZeroLength); - using (var name = RuntimeMarshal.MarshalString(assemblyName)) + using (SafeStringMarshal name = RuntimeMarshal.MarshalString(assemblyName)) { // TODO: Should use CoreRT AssemblyNameParser - if (!ParseAssemblyName(name.Value, out var nativeName, out var isVersionDefined, out var isTokenDefined)) + if (!ParseAssemblyName(name.Value, out MonoAssemblyName nativeName, out bool isVersionDefined, out bool isTokenDefined)) throw new FileLoadException("The assembly name is invalid."); try @@ -78,8 +78,8 @@ internal unsafe void FillName(MonoAssemblyName* native, string codeBase, bool ad if (addVersion) { - var build = native->build == 65535 ? -1 : native->build; - var revision = native->revision == 65535 ? -1 : native->revision; + int build = native->build == 65535 ? -1 : native->build; + int revision = native->revision == 65535 ? -1 : native->revision; if (build == -1) _version = new Version(native->major, native->minor); @@ -126,7 +126,7 @@ private static AssemblyName GetFileInformationCore(string assemblyFile) { unsafe { - Assembly.InternalGetAssemblyName(Path.GetFullPath(assemblyFile), out var nativeName, out var codebase); + Assembly.InternalGetAssemblyName(Path.GetFullPath(assemblyFile), out MonoAssemblyName nativeName, out string? codebase); var aname = new AssemblyName(); try diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs index cc141613b5e11..1e3882d8ed445 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs @@ -23,9 +23,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -using System; -using System.Reflection; -using System.Collections; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -85,7 +82,7 @@ internal static object[] GetPseudoCustomAttributes(ICustomAttributeProvider obj, private static object[] GetPseudoCustomAttributes(Type type) { int count = 0; - var Attributes = type.Attributes; + TypeAttributes Attributes = type.Attributes; /* IsSerializable returns true for delegates/enums as well */ if ((Attributes & TypeAttributes.Serializable) != 0) @@ -192,7 +189,7 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type inherit = false; } - var initialSize = Math.Max(res.Length, 16); + int initialSize = Math.Max(res.Length, 16); List a = null; ICustomAttributeProvider btype = obj; object[] array; @@ -362,12 +359,12 @@ internal static IList GetCustomAttributesData(ICustomAttrib // there's no use in scanning base types if ((attributeType != null && attributeType.IsSealed) && inherit) { - var usageAttribute = RetrieveAttributeUsage(attributeType); + AttributeUsageAttribute? usageAttribute = RetrieveAttributeUsage(attributeType); if (!usageAttribute.Inherited) inherit = false; } - var initialSize = Math.Max(res.Count, 16); + int initialSize = Math.Max(res.Count, 16); List a = null; ICustomAttributeProvider btype = obj; @@ -527,7 +524,7 @@ internal static CustomAttributeData[] GetPseudoCustomAttributesData(ICustomAttri private static CustomAttributeData[] GetPseudoCustomAttributesData(Type type) { int count = 0; - var Attributes = type.Attributes; + TypeAttributes Attributes = type.Attributes; /* IsSerializable returns true for delegates/enums as well */ if ((Attributes & TypeAttributes.Serializable) != 0) @@ -661,7 +658,7 @@ private static ICustomAttributeProvider GetBase(ICustomAttributeProvider obj) method = (MethodInfo)obj; if (obj is RuntimeParameterInfo parinfo) { - var member = parinfo.Member; + MemberInfo? member = parinfo.Member; if (member is MethodInfo) { method = (MethodInfo)member; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeData.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeData.cs index 6b011450235d8..0a28c73709420 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeData.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeData.cs @@ -27,7 +27,6 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Text; namespace System.Reflection diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs index 6fad5aa52ce3e..45bd19b250551 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs @@ -32,18 +32,11 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; using System.IO; -using System.Runtime.Serialization; using System.Globalization; using System.Runtime.CompilerServices; -using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Security; -using System.Security.Cryptography; -using System.Threading; namespace System.Reflection.Emit { @@ -301,10 +294,10 @@ public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyB public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable assemblyAttributes) { - var ab = DefineDynamicAssembly(name, access); + AssemblyBuilder ab = DefineDynamicAssembly(name, access); if (assemblyAttributes != null) { - foreach (var attr in assemblyAttributes) + foreach (CustomAttributeBuilder attr in assemblyAttributes) ab.SetCustomAttribute(attr); } @@ -497,7 +490,7 @@ public override Type GetType(string name, bool throwOnError, bool ignoreCase) if (name.Length == 0) throw new ArgumentException("Name cannot be empty", nameof(name)); - var res = InternalGetType(null, name, throwOnError, ignoreCase); + Type res = InternalGetType(null, name, throwOnError, ignoreCase); if (res is TypeBuilder) { if (throwOnError) diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs index 3d55f212e7e53..ac5c287465097 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs @@ -32,13 +32,8 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Reflection.Emit; using System.Globalization; using System.Runtime.InteropServices; -using System.Diagnostics.SymbolStore; namespace System.Reflection.Emit { @@ -355,12 +350,12 @@ internal void ResolveUserTypes() TypeBuilder.ResolveUserTypes(parameters); if (paramModReq != null) { - foreach (var types in paramModReq) + foreach (Type[] types in paramModReq) TypeBuilder.ResolveUserTypes(types); } if (paramModOpt != null) { - foreach (var types in paramModOpt) + foreach (Type[] types in paramModOpt) TypeBuilder.ResolveUserTypes(types); } } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorOnTypeBuilderInst.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorOnTypeBuilderInst.cs index 1dbccc9b6d7bb..2cf4fe9f7b753 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorOnTypeBuilderInst.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorOnTypeBuilderInst.cs @@ -29,9 +29,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System; using System.Globalization; -using System.Reflection; using System.Runtime.InteropServices; namespace System.Reflection.Emit @@ -125,9 +123,8 @@ public override ParameterInfo[] GetParameters() internal override ParameterInfo[] GetParametersInternal() { ParameterInfo[] res; - if (cb is ConstructorBuilder) + if (cb is ConstructorBuilder cbuilder) { - ConstructorBuilder cbuilder = (ConstructorBuilder)cb; res = new ParameterInfo[cbuilder.parameters.Length]; for (int i = 0; i < cbuilder.parameters.Length; i++) { @@ -169,7 +166,7 @@ internal override Type[] GetParameterTypes() // Called from the runtime to return the corresponding finished ConstructorInfo object internal ConstructorInfo RuntimeResolve() { - var type = instantiation.InternalResolve(); + Type type = instantiation.InternalResolve(); return type.GetConstructor(cb); } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs index 6f9c751d1da7b..3b7921596eeef 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs @@ -32,9 +32,6 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; -using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -151,7 +148,7 @@ private static bool IsValidValue(Type type, object value) return false; if (type.IsArray && type.GetElementType().IsValueType) { - foreach (var v in (Array)value) + foreach (object v in (Array)value) { if (v == null) return false; @@ -436,41 +433,25 @@ internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuild } } - private static Type elementTypeToType(int elementType) - { + private static Type elementTypeToType(int elementType) => /* Partition II, section 23.1.16 */ - switch (elementType) + elementType switch { - case 0x02: - return typeof(bool); - case 0x03: - return typeof(char); - case 0x04: - return typeof(sbyte); - case 0x05: - return typeof(byte); - case 0x06: - return typeof(short); - case 0x07: - return typeof(ushort); - case 0x08: - return typeof(int); - case 0x09: - return typeof(uint); - case 0x0a: - return typeof(long); - case 0x0b: - return typeof(ulong); - case 0x0c: - return typeof(float); - case 0x0d: - return typeof(double); - case 0x0e: - return typeof(string); - default: - throw new Exception("Unknown element type '" + elementType + "'"); - } - } + 0x02 => typeof(bool), + 0x03 => typeof(char), + 0x04 => typeof(sbyte), + 0x05 => typeof(byte), + 0x06 => typeof(short), + 0x07 => typeof(ushort), + 0x08 => typeof(int), + 0x09 => typeof(uint), + 0x0a => typeof(long), + 0x0b => typeof(ulong), + 0x0c => typeof(float), + 0x0d => typeof(double), + 0x0e => typeof(string), + _ => throw new Exception("Unknown element type '" + elementType + "'"), + }; private static object decode_cattr_value(Type t, byte[] data, int pos, out int rpos) { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs index 7be3181fc7b1a..a0d54a683420a 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs @@ -29,13 +29,8 @@ #nullable disable #if MONO_FEATURE_SRE -using System.Reflection; -using System.Reflection.Emit; -using System.Collections; -using System.Runtime.CompilerServices; using System.Globalization; using System.Runtime.InteropServices; -using System.Runtime.Serialization; using System.Text; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILInfo.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILInfo.cs index e2cf318f7b309..ef5e71476e343 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILInfo.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILInfo.cs @@ -28,8 +28,6 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; using System.Runtime.InteropServices; namespace System.Reflection.Emit diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs index 3625b488b930d..6d3efae784386 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs @@ -34,10 +34,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System; using System.Text; -using System.Reflection; -using System.Reflection.Emit; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -91,7 +88,7 @@ public DynamicMethod(string name, Type returnType, Type[] parameterTypes, Type o { } - public DynamicMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility) : this(name, attributes, callingConvention, returnType, parameterTypes, owner, owner != null ? owner.Module : null, skipVisibility, false, true) + public DynamicMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility) : this(name, attributes, callingConvention, returnType, parameterTypes, owner, owner?.Module, skipVisibility, false, true) { } @@ -167,9 +164,8 @@ private void CreateDynMethod() { for (int i = 0; i < refs.Length; ++i) { - if (refs[i] is DynamicMethod) + if (refs[i] is DynamicMethod m) { - DynamicMethod m = (DynamicMethod)refs[i]; if (!m.creating) m.CreateDynMethod(); } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs index 507f4c302ae16..510473f4935d2 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs @@ -32,9 +32,6 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; -using System.Reflection.Emit; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs index 96c9d2cd9a284..edfb3cde0fb89 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs @@ -32,11 +32,6 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; -using System.Reflection.Emit; -using System.Globalization; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Reflection.Emit diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventOnTypeBuilderInst.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventOnTypeBuilderInst.cs index 44014905f44b8..8eca4ede14b0e 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventOnTypeBuilderInst.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventOnTypeBuilderInst.cs @@ -29,10 +29,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System; using System.Collections; -using System.Globalization; -using System.Reflection; using System.Runtime.InteropServices; namespace System.Reflection.Emit diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs index 17ef8ec60eb7c..9622bc879ea88 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs @@ -32,11 +32,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; -using System.Reflection.Emit; using System.Globalization; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Reflection.Emit diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldOnTypeBuilderInst.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldOnTypeBuilderInst.cs index ec2a5b580c209..2d3f08d155153 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldOnTypeBuilderInst.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldOnTypeBuilderInst.cs @@ -29,9 +29,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System; using System.Globalization; -using System.Reflection; using System.Runtime.InteropServices; namespace System.Reflection.Emit @@ -149,7 +147,7 @@ public override void SetValue(object obj, object value, BindingFlags invokeAttr, // Called from the runtime to return the corresponding finished FieldInfo object internal FieldInfo RuntimeResolve() { - var type = instantiation.RuntimeResolve(); + Type type = instantiation.RuntimeResolve(); return type.GetField(fb); } } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs index ff90c6bc82e13..2bde022d239bf 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs @@ -31,13 +31,8 @@ #nullable disable #if MONO_FEATURE_SRE -using System.Reflection; -using System.Reflection.Emit; -using System.Collections; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Globalization; -using System.Runtime.Serialization; namespace System.Reflection.Emit { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index cbf4cf3aec829..af881e07363c3 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -32,7 +32,6 @@ #nullable disable #if MONO_FEATURE_SRE -using System; using System.Collections.Generic; using System.Diagnostics.SymbolStore; using System.Runtime.InteropServices; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/LocalBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/LocalBuilder.Mono.cs index f15eaf10e2ced..94bdf1d26881a 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/LocalBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/LocalBuilder.Mono.cs @@ -33,12 +33,7 @@ // #nullable disable -using System; -using System.Reflection; -using System.Globalization; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Diagnostics.SymbolStore; namespace System.Reflection.Emit { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs index f9fe0b33632ed..76a577a412951 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs @@ -32,14 +32,8 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; -using System.Reflection.Emit; using System.Globalization; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Diagnostics.SymbolStore; -using System.Collections.Generic; namespace System.Reflection.Emit { @@ -358,7 +352,7 @@ internal void check_override() { if (override_methods != null) { - foreach (var m in override_methods) + foreach (MethodInfo m in override_methods) { if (m.IsVirtual && !IsVirtual) throw new TypeLoadException(string.Format("Method '{0}' override '{1}' but it is not virtual", name, m)); @@ -388,12 +382,12 @@ internal void ResolveUserTypes() TypeBuilder.ResolveUserTypes(returnModOpt); if (paramModReq != null) { - foreach (var types in paramModReq) + foreach (Type[] types in paramModReq) TypeBuilder.ResolveUserTypes(types); } if (paramModOpt != null) { - foreach (var types in paramModOpt) + foreach (Type[] types in paramModOpt) TypeBuilder.ResolveUserTypes(types); } } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs index ff11c1e69ce5a..0ef9a73e99d89 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs @@ -29,9 +29,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System; using System.Globalization; -using System.Reflection; using System.Text; using System.Runtime.InteropServices; @@ -104,8 +102,8 @@ internal Type[] GetTypeArgs() // Called from the runtime to return the corresponding finished MethodInfo object internal MethodInfo RuntimeResolve() { - var type = instantiation.InternalResolve(); - var m = type.GetMethod(base_method); + Type type = instantiation.InternalResolve(); + MethodInfo m = type.GetMethod(base_method); if (method_arguments != null) { var args = new Type[method_arguments.Length]; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs index 75eb11e19b7f1..c9e6f1f7e4461 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs @@ -32,13 +32,9 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; -using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Diagnostics.SymbolStore; using System.IO; using System.Globalization; @@ -143,7 +139,7 @@ public FieldBuilder DefineInitializedData(string name, byte[] data, FieldAttribu if (data == null) throw new ArgumentNullException(nameof(data)); - var maskedAttributes = attributes & ~FieldAttributes.ReservedMask; + FieldAttributes maskedAttributes = attributes & ~FieldAttributes.ReservedMask; FieldBuilder fb = DefineDataImpl(name, data.Length, maskedAttributes | FieldAttributes.HasFieldRVA); fb.SetRVAData(data); @@ -426,7 +422,7 @@ public override Type GetType(string className, bool throwOnError, bool ignoreCas if (!ignoreCase) { - var displayNestedName = ts.TypeNameWithoutModifiers(); + ITypeName displayNestedName = ts.TypeNameWithoutModifiers(); name_cache.TryGetValue(displayNestedName, out result); } else @@ -449,7 +445,7 @@ public override Type GetType(string className, bool throwOnError, bool ignoreCas if (tb.is_created) mt = tb.CreateType(); } - foreach (var mod in ts.Modifiers) + foreach (IModifierSpec mod in ts.Modifiers) { if (mod is PointerSpec) mt = mt.MakePointerType(); @@ -487,7 +483,7 @@ internal int get_next_table_index(object obj, int table, int count) table_indexes[0x02] = 2; } // Console.WriteLine ("getindex for table "+table.ToString()+" got "+table_indexes [table].ToString()); - var index = table_indexes[table]; + int index = table_indexes[table]; table_indexes[table] += count; return index; } @@ -647,7 +643,7 @@ internal int GetToken(string str) private int GetPseudoToken(MemberInfo member, bool create_open_instance) { int token; - var dict = create_open_instance ? inst_tokens_open : inst_tokens; + Dictionary dict = create_open_instance ? inst_tokens_open : inst_tokens; if (dict == null) { dict = new Dictionary(ReferenceEqualityComparer.Instance); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MonoArrayMethod.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MonoArrayMethod.cs index 812d0472dd272..ce3dfe77f1639 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MonoArrayMethod.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MonoArrayMethod.cs @@ -33,9 +33,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System; using System.Globalization; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Reflection diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.Mono.cs index f08aef59e1c02..3b0dbd164d518 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.Mono.cs @@ -33,11 +33,6 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; -using System.Reflection.Emit; -using System.Globalization; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Reflection.Emit diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs index a51afbbf79d8b..78d9c6be13ac4 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs @@ -32,11 +32,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; -using System.Reflection.Emit; using System.Globalization; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Reflection.Emit diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs index 3a02bca556d66..da83ae6087ba0 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs @@ -29,9 +29,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System; using System.Globalization; -using System.Reflection; using System.Runtime.InteropServices; namespace System.Reflection.Emit diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs index 2768f392258ec..11831136454d9 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs @@ -32,10 +32,6 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Reflection; -using System.Reflection.Emit; -using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -238,9 +234,7 @@ public void AddArguments(Type[] arguments, Type[][] requiredCustomModifiers, Typ for (int i = 0; i < arguments.Length; i++) { - AddArgument(arguments[i], - requiredCustomModifiers != null ? requiredCustomModifiers[i] : null, - optionalCustomModifiers != null ? optionalCustomModifiers[i] : null); + AddArgument(arguments[i], requiredCustomModifiers?[i], optionalCustomModifiers?[i]); } } @@ -378,15 +372,12 @@ public byte[] GetSignature() { TypeBuilder.ResolveUserTypes(arguments); - switch (type) + return type switch { - case SignatureHelperType.HELPER_LOCAL: - return get_signature_local(); - case SignatureHelperType.HELPER_FIELD: - return get_signature_field(); - default: - throw new NotImplementedException(); - } + SignatureHelperType.HELPER_LOCAL => get_signature_local(), + SignatureHelperType.HELPER_FIELD => get_signature_field(), + _ => throw new NotImplementedException(), + }; } public override string ToString() diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index 573f1619d0228..be4c117f434ce 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -33,16 +33,10 @@ #nullable disable #if MONO_FEATURE_SRE -using System; -using System.Text; -using System.Reflection; -using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Globalization; using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.SymbolStore; namespace System.Reflection.Emit { @@ -651,9 +645,8 @@ public void DefineMethodOverride(MethodInfo methodInfoBody, MethodInfo methodInf if (methodInfoBody.DeclaringType != this) throw new ArgumentException("method body must belong to this type"); - if (methodInfoBody is MethodBuilder) + if (methodInfoBody is MethodBuilder mb) { - MethodBuilder mb = (MethodBuilder)methodInfoBody; mb.set_override(methodInfoDeclaration); } } @@ -802,9 +795,9 @@ TypeInfo CreateTypeInfo() if (fb == null) continue; Type ft = fb.FieldType; - if (!fb.IsStatic && (ft is TypeBuilder) && ft.IsValueType && (ft != this) && is_nested_in(ft)) + if (!fb.IsStatic && (ft is TypeBuilder builder) && ft.IsValueType && (ft != this) && is_nested_in(ft)) { - TypeBuilder tb = (TypeBuilder)ft; + TypeBuilder tb = builder; if (!tb.is_created) { throw new NotImplementedException(); @@ -842,7 +835,7 @@ TypeInfo CreateTypeInfo() throw new TypeLoadException("Could not load type '" + FullName + "' from assembly '" + Assembly + "' because it is an enum with methods."); if (interfaces != null) { - foreach (var iface in interfaces) + foreach (Type iface in interfaces) { if (iface.IsNestedPrivate && iface.Assembly != Assembly) throw new TypeLoadException("Could not load type '" + FullName + "' from assembly '" + Assembly + "' because it is implements the inaccessible interface '" + iface.FullName + "'."); @@ -850,7 +843,7 @@ TypeInfo CreateTypeInfo() throw new BadImageFormatException(); if (!iface.IsInterface) throw new TypeLoadException(); - if (iface is TypeBuilder && !((TypeBuilder)iface).is_created) + if (iface is TypeBuilder builder && !builder.is_created) throw new TypeLoadException(); } } @@ -899,7 +892,7 @@ private void ResolveUserTypes() ResolveUserTypes(interfaces); if (fields != null) { - foreach (var fb in fields) + foreach (FieldBuilder fb in fields) { if (fb != null) fb.ResolveUserTypes(); @@ -907,7 +900,7 @@ private void ResolveUserTypes() } if (methods != null) { - foreach (var mb in methods) + foreach (MethodBuilder mb in methods) { if (mb != null) mb.ResolveUserTypes(); @@ -915,7 +908,7 @@ private void ResolveUserTypes() } if (ctors != null) { - foreach (var cb in ctors) + foreach (ConstructorBuilder cb in ctors) { if (cb != null) cb.ResolveUserTypes(); @@ -1117,21 +1110,13 @@ private MethodInfo[] GetMethodsByName(string name, BindingFlags bindingAttr, boo if (m.IsStatic && !flatten) continue; - switch (mattrs & MethodAttributes.MemberAccessMask) + match = (mattrs & MethodAttributes.MemberAccessMask) switch { - case MethodAttributes.Public: - match = (bindingAttr & BindingFlags.Public) != 0; - break; - case MethodAttributes.Assembly: - match = (bindingAttr & BindingFlags.NonPublic) != 0; - break; - case MethodAttributes.Private: - match = false; - break; - default: - match = (bindingAttr & BindingFlags.NonPublic) != 0; - break; - } + MethodAttributes.Public => (bindingAttr & BindingFlags.Public) != 0, + MethodAttributes.Assembly => (bindingAttr & BindingFlags.NonPublic) != 0, + MethodAttributes.Private => false, + _ => (bindingAttr & BindingFlags.NonPublic) != 0, + }; if (match) parent_candidates.Add(m); @@ -1421,23 +1406,15 @@ public void SetCustomAttribute(CustomAttributeBuilder customBuilder) layout_kind = (int)data[2]; layout_kind |= ((int)data[3]) << 8; attrs &= ~TypeAttributes.LayoutMask; - switch ((LayoutKind)layout_kind) + attrs |= ((LayoutKind)layout_kind) switch { - case LayoutKind.Auto: - attrs |= TypeAttributes.AutoLayout; - break; - case LayoutKind.Explicit: - attrs |= TypeAttributes.ExplicitLayout; - break; - case LayoutKind.Sequential: - attrs |= TypeAttributes.SequentialLayout; - break; - default: - // we should ignore it since it can be any value anyway... - throw new Exception("Error in customattr"); - } + LayoutKind.Auto => TypeAttributes.AutoLayout, + LayoutKind.Explicit => TypeAttributes.ExplicitLayout, + LayoutKind.Sequential => TypeAttributes.SequentialLayout, + _ => throw new Exception("Error in customattr"), // we should ignore it since it can be any value anyway... + }; - var ctor_type = customBuilder.Ctor is ConstructorBuilder ? ((ConstructorBuilder)customBuilder.Ctor).parameters[0] : customBuilder.Ctor.GetParametersInternal()[0].ParameterType; + Type ctor_type = customBuilder.Ctor is ConstructorBuilder builder ? builder.parameters[0] : customBuilder.Ctor.GetParametersInternal()[0].ParameterType; int pos = 6; if (ctor_type.FullName == "System.Int16") pos = 4; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs index a5cc6e15cd565..5ac123dff05c9 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs @@ -33,12 +33,8 @@ #nullable disable #if MONO_FEATURE_SRE -using System.Reflection; -using System.Reflection.Emit; using System.Collections; -using System.Runtime.CompilerServices; using System.Globalization; -using System.Runtime.Serialization; using System.Text; using System.Runtime.InteropServices; @@ -88,7 +84,7 @@ internal override Type RuntimeResolve() throw new NotImplementedException(); for (int i = 0; i < type_arguments.Length; ++i) { - var t = type_arguments[i]; + Type t = type_arguments[i]; if (t is TypeBuilder && !(t as TypeBuilder).IsCreated()) throw new NotImplementedException(); } @@ -99,13 +95,11 @@ internal bool IsCreated { get { - TypeBuilder tb = generic_type as TypeBuilder; - return tb != null ? tb.is_created : true; + return generic_type is TypeBuilder tb ? tb.is_created : true; } } - private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | - BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; + private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; private Type GetParentType() { @@ -509,7 +503,7 @@ internal override bool IsUserType { get { - foreach (var t in type_arguments) + foreach (Type t in type_arguments) { if (t.IsUserType) return true; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/UnmanagedMarshal.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/UnmanagedMarshal.cs index 8e979856ad4ca..cf6bd60fa6464 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/UnmanagedMarshal.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/UnmanagedMarshal.cs @@ -32,9 +32,7 @@ #nullable disable #if MONO_FEATURE_SRE -using System.Reflection.Emit; using System.Runtime.InteropServices; -using System; namespace System.Reflection.Emit { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/MethodBase.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/MethodBase.Mono.cs index 7db4d6d3e1523..325f7ab099099 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/MethodBase.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/MethodBase.Mono.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; -using System.Reflection.Emit; namespace System.Reflection { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 3d1d81df47375..c23f978d7404a 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -61,7 +61,7 @@ public unsafe UnmanagedMemoryStreamForModule(byte* pointer, long length, Module private ResolveEventHolder resolve_event_holder; - public override extern MethodInfo? EntryPoint + public extern override MethodInfo? EntryPoint { [MethodImplAttribute(MethodImplOptions.InternalCall)] get; @@ -144,10 +144,10 @@ internal static AssemblyName CreateAssemblyName(string assemblyString, out Runti } [MethodImplAttribute(MethodImplOptions.InternalCall)] - public override extern string[] GetManifestResourceNames(); + public extern override string[] GetManifestResourceNames(); [MethodImplAttribute(MethodImplOptions.InternalCall)] - public override extern Type[] GetExportedTypes(); + public extern override Type[] GetExportedTypes(); [MethodImplAttribute(MethodImplOptions.InternalCall)] internal extern Type[] GetTopLevelForwardedTypes(); @@ -319,7 +319,7 @@ public override AssemblyName[] GetReferencedAssemblies() { using (var nativeNames = new Mono.SafeGPtrArrayHandle(InternalGetReferencedAssemblies(this))) { - var numAssemblies = nativeNames.Length; + int numAssemblies = nativeNames.Length; try { AssemblyName[] result = new AssemblyName[numAssemblies]; @@ -368,7 +368,7 @@ public override Assembly GetSatelliteAssembly(CultureInfo culture, Version versi [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod internal Assembly InternalGetSatelliteAssembly(CultureInfo culture, Version version, bool throwOnFileNotFound) { - var aname = GetName(); + AssemblyName aname = GetName(); var an = new AssemblyName(); if (version == null) diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs index 1ad52ff27b979..29c401bd291a2 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs @@ -83,7 +83,7 @@ internal RuntimeModule GetRuntimeModule() } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal override extern object UnsafeGetValue(object obj); + internal extern override object UnsafeGetValue(object obj); internal override void CheckConsistency(object target) { @@ -211,7 +211,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal override extern int GetFieldOffset(); + internal extern override int GetFieldOffset(); [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern object GetValueInternal(object obj); @@ -279,7 +279,7 @@ internal RuntimeFieldInfo Clone(string newName) } [MethodImplAttribute(MethodImplOptions.InternalCall)] - public override extern object GetRawConstantValue(); + public extern override object GetRawConstantValue(); public override IList GetCustomAttributesData() { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeLocalVariableInfo.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeLocalVariableInfo.cs index 1f955d6735f1f..a7fff4fb28c84 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeLocalVariableInfo.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeLocalVariableInfo.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Reflection diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs index 97c20ed88b2b7..627d4cae5791a 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs @@ -2,10 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; namespace System.Reflection { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs index 3bb9184855866..27a619be3b000 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs @@ -296,7 +296,7 @@ public override MethodImplAttributes GetMethodImplementationFlags() public override ParameterInfo[] GetParameters() { - var src = MonoMethodInfo.GetParametersInfo(mhandle, this); + ParameterInfo[] src = MonoMethodInfo.GetParametersInfo(mhandle, this); if (src.Length == 0) return src; @@ -404,8 +404,8 @@ internal static void ConvertValues(Binder binder, object[] args, ParameterInfo[] for (int i = 0; i < args.Length; ++i) { - var arg = args[i]; - var pi = pinfo[i]; + object arg = args[i]; + ParameterInfo pi = pinfo[i]; if (arg == Type.Missing) { if (pi.DefaultValue == DBNull.Value) @@ -601,52 +601,26 @@ private CustomAttributeData GetDllImportAttributeData() GetPInvoke(out flags, out entryPoint, out dllName); - CharSet charSet; - - switch (flags & PInvokeAttributes.CharSetMask) + CharSet charSet = (flags & PInvokeAttributes.CharSetMask) switch { - case PInvokeAttributes.CharSetNotSpec: - charSet = CharSet.None; - break; - case PInvokeAttributes.CharSetAnsi: - charSet = CharSet.Ansi; - break; - case PInvokeAttributes.CharSetUnicode: - charSet = CharSet.Unicode; - break; - case PInvokeAttributes.CharSetAuto: - charSet = CharSet.Auto; - break; + PInvokeAttributes.CharSetNotSpec => CharSet.None, + PInvokeAttributes.CharSetAnsi => CharSet.Ansi, + PInvokeAttributes.CharSetUnicode => CharSet.Unicode, + PInvokeAttributes.CharSetAuto => CharSet.Auto, // Invalid: default to CharSet.None - default: - charSet = CharSet.None; - break; - } - - InteropServicesCallingConvention callingConvention; + _ => CharSet.None, + }; - switch (flags & PInvokeAttributes.CallConvMask) + InteropServicesCallingConvention callingConvention = (flags & PInvokeAttributes.CallConvMask) switch { - case PInvokeAttributes.CallConvWinapi: - callingConvention = InteropServicesCallingConvention.Winapi; - break; - case PInvokeAttributes.CallConvCdecl: - callingConvention = InteropServicesCallingConvention.Cdecl; - break; - case PInvokeAttributes.CallConvStdcall: - callingConvention = InteropServicesCallingConvention.StdCall; - break; - case PInvokeAttributes.CallConvThiscall: - callingConvention = InteropServicesCallingConvention.ThisCall; - break; - case PInvokeAttributes.CallConvFastcall: - callingConvention = InteropServicesCallingConvention.FastCall; - break; + PInvokeAttributes.CallConvWinapi => InteropServicesCallingConvention.Winapi, + PInvokeAttributes.CallConvCdecl => InteropServicesCallingConvention.Cdecl, + PInvokeAttributes.CallConvStdcall => InteropServicesCallingConvention.StdCall, + PInvokeAttributes.CallConvThiscall => InteropServicesCallingConvention.ThisCall, + PInvokeAttributes.CallConvFastcall => InteropServicesCallingConvention.FastCall, // Invalid: default to CallingConvention.Cdecl - default: - callingConvention = InteropServicesCallingConvention.Cdecl; - break; - } + _ => InteropServicesCallingConvention.Cdecl, + }; bool exactSpelling = (flags & PInvokeAttributes.NoMangle) != 0; bool setLastError = (flags & PInvokeAttributes.SupportsLastError) != 0; @@ -658,7 +632,7 @@ private CustomAttributeData GetDllImportAttributeData() new CustomAttributeTypedArgument (typeof(string), dllName), }; - var attrType = typeof(DllImportAttribute); + Type attrType = typeof(DllImportAttribute); var namedArgs = new CustomAttributeNamedArgument[] { new CustomAttributeNamedArgument (attrType.GetField ("EntryPoint"), entryPoint), @@ -716,7 +690,7 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) private extern MethodInfo MakeGenericMethod_impl(Type[] types); [MethodImplAttribute(MethodImplOptions.InternalCall)] - public override extern Type[] GetGenericArguments(); + public extern override Type[] GetGenericArguments(); [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern MethodInfo GetGenericMethodDefinition_impl(); @@ -730,13 +704,13 @@ public override MethodInfo GetGenericMethodDefinition() return res; } - public override extern bool IsGenericMethodDefinition + public extern override bool IsGenericMethodDefinition { [MethodImplAttribute(MethodImplOptions.InternalCall)] get; } - public override extern bool IsGenericMethod + public extern override bool IsGenericMethod { [MethodImplAttribute(MethodImplOptions.InternalCall)] get; @@ -824,7 +798,7 @@ internal override ParameterInfo[] GetParametersInternal() internal override int GetParametersCount() { - var pi = MonoMethodInfo.GetParametersInfo(mhandle, this); + ParameterInfo[] pi = MonoMethodInfo.GetParametersInfo(mhandle, this); return pi == null ? 0 : pi.Length; } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs index 42dd0e2f2cf38..b6a58015e12f1 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs @@ -22,7 +22,6 @@ // #nullable disable -using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -141,7 +140,7 @@ FieldInfo GetField(string name, BindingFlags bindingAttr) return null; Type globalType = GetGlobalType(_impl); - return (globalType != null) ? globalType.GetField(name, bindingAttr) : null; + return globalType?.GetField(name, bindingAttr); } public override diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs index c7df70df12ef7..c5dfc61868e96 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs @@ -164,12 +164,9 @@ int MetadataToken { get { - if (MemberImpl is PropertyInfo) + if (MemberImpl is PropertyInfo prop) { - PropertyInfo prop = (PropertyInfo)MemberImpl; - MethodInfo mi = prop.GetGetMethod(true); - if (mi == null) - mi = prop.GetSetMethod(true); + MethodInfo mi = prop.GetGetMethod(true) ?? prop.GetSetMethod(true); return mi.GetParametersInternal()[PositionImpl].MetadataToken; } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index 9eca88b3d7d43..5d14b5aa0f7e1 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -154,7 +154,7 @@ private string FormatNameAndSig() sbName.Append(" "); sbName.Append(Name); - var pi = GetIndexParameters(); + ParameterInfo[] pi = GetIndexParameters(); if (pi.Length > 0) { sbName.Append(" ["); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs index 12bf24216cc0b..063809177c831 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; @@ -317,7 +316,7 @@ private static void PtrToStructureHelper(IntPtr ptr, object structure, bool allo private static object PtrToStructureHelper(IntPtr ptr, Type structureType) { - var obj = Activator.CreateInstance(structureType); + object? obj = Activator.CreateInstance(structureType); PtrToStructureHelper(ptr, obj, true); return obj; } @@ -341,7 +340,7 @@ public static IntPtr GetExceptionPointers() internal static unsafe IntPtr AllocBSTR(int length) { - var res = BufferToBSTR((char*)IntPtr.Zero, length); + IntPtr res = BufferToBSTR((char*)IntPtr.Zero, length); if (res == IntPtr.Zero) throw new OutOfMemoryException(); return res; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs index bfd7ce58d34c1..aad31f3620b8b 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.IO; using System.Reflection; using System.Runtime.CompilerServices; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.Mono.cs index b36730f7901fa..f3a3999778897 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.Mono.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.CompilerServices; - namespace System.Runtime.InteropServices { // Mono runtime relies on exact layout diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeFieldHandle.cs b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeFieldHandle.cs index 159ffbdec78b5..fd1d24ff6a486 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeFieldHandle.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeFieldHandle.cs @@ -78,10 +78,10 @@ internal static void SetValue(RuntimeFieldInfo field, object obj, object value, } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static unsafe extern object GetValueDirect(RuntimeFieldInfo field, RuntimeType fieldType, void* pTypedRef, RuntimeType contextType); + internal static extern unsafe object GetValueDirect(RuntimeFieldInfo field, RuntimeType fieldType, void* pTypedRef, RuntimeType contextType); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static unsafe extern void SetValueDirect(RuntimeFieldInfo field, RuntimeType fieldType, void* pTypedRef, object value, RuntimeType contextType); + internal static extern unsafe void SetValueDirect(RuntimeFieldInfo field, RuntimeType fieldType, void* pTypedRef, object value, RuntimeType contextType); } } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeMethodHandle.cs b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeMethodHandle.cs index c1119fcbcdc74..62c5110f1a378 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeMethodHandle.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeMethodHandle.cs @@ -5,7 +5,6 @@ using System.Reflection; using System.Runtime.Serialization; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Text; namespace System @@ -71,7 +70,7 @@ public override int GetHashCode() internal static string ConstructInstantiation(RuntimeMethodInfo method, TypeNameFormatFlags format) { var sb = new StringBuilder(); - var gen_params = method.GetGenericArguments(); + Type[]? gen_params = method.GetGenericArguments(); sb.Append("["); for (int j = 0; j < gen_params.Length; j++) { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index a7d1bd3fc23e8..b6e032e1c533b 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -601,7 +601,7 @@ private static bool FilterApplyPrefixLookup(MemberInfo memberInfo, string name, continue; else if (genericParamCount > 0 && !is_generic) continue; - var args = methodInfo.GetGenericArguments(); + Type[]? args = methodInfo.GetGenericArguments(); if (args.Length != genericParamCount) continue; } @@ -897,7 +897,7 @@ protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAtt } else { - if ((object)returnType == null) + if (returnType is null) // if we are here we have no args or property type to select over and we have more than one property with that name throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException")); } @@ -999,7 +999,7 @@ public override Type GetInterface(string fullname, bool ignoreCase) FilterHelper(bindingAttr, ref name, out ignoreCase, out listType); List list = null; - var nameComparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; + StringComparison nameComparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; foreach (RuntimeType t in GetInterfaces()) { @@ -1017,7 +1017,7 @@ public override Type GetInterface(string fullname, bool ignoreCase) if (list == null) return null; - var cache = list.ToArray(); + RuntimeType[]? cache = list.ToArray(); RuntimeType match = null; for (int i = 0; i < cache.Length; i++) @@ -1155,7 +1155,7 @@ public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFla public override bool IsEquivalentTo(Type? other) { RuntimeType otherRtType = other as RuntimeType; - if ((object)otherRtType == null) + if (otherRtType is null) return false; if (otherRtType == this) @@ -1568,12 +1568,7 @@ public override int GenericParameterPosition } else { - if (results == null) - { - results = new List(semiFinalists.Length); - results.Add(finalist); - } - + results ??= new List(semiFinalists.Length) { finalist }; results.Add(semiFinalist); } } @@ -1622,12 +1617,7 @@ public override int GenericParameterPosition } else { - if (results == null) - { - results = new List(semiFinalists.Length); - results.Add(finalist); - } - + results ??= new List(semiFinalists.Length) { finalist }; results.Add(semiFinalist); } } @@ -1872,13 +1862,13 @@ internal RuntimeType(object obj) internal RuntimeConstructorInfo GetDefaultConstructor() { - var cache = Cache; + TypeCache? cache = Cache; RuntimeConstructorInfo ctor = null; if (Volatile.Read(ref cache.default_ctor_cached)) return cache.default_ctor; - var ctors = GetConstructorCandidates( + ListBuilder ctors = GetConstructorCandidates( null, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly, CallingConventions.Any, Array.Empty(), false); @@ -1961,7 +1951,7 @@ internal object CreateInstanceSlow(bool publicOnly, bool wrapExceptions, bool sk private object CreateInstanceMono(bool nonPublic, bool wrapExceptions) { - var ctor = GetDefaultConstructor(); + RuntimeConstructorInfo? ctor = GetDefaultConstructor(); if (!nonPublic && ctor != null && !ctor.IsPublic) { throw new MissingMethodException(SR.Format(SR.Arg_NoDefCTor, FullName)); @@ -1991,7 +1981,7 @@ private object CreateInstanceMono(bool nonPublic, bool wrapExceptions) internal object CheckValue(object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) { bool failed = false; - var res = TryConvertToType(value, ref failed); + object? res = TryConvertToType(value, ref failed); if (!failed) return res; @@ -2013,7 +2003,7 @@ private object TryConvertToType(object value, ref bool failed) if (IsByRef) { - var elementType = GetElementType(); + Type? elementType = GetElementType(); if (value == null || elementType.IsInstanceOfType(value)) { return value; @@ -2025,22 +2015,22 @@ private object TryConvertToType(object value, ref bool failed) if (IsEnum) { - var type = Enum.GetUnderlyingType(this); + Type? type = Enum.GetUnderlyingType(this); if (type == value.GetType()) return value; - var res = IsConvertibleToPrimitiveType(value, this); + object? res = IsConvertibleToPrimitiveType(value, this); if (res != null) return res; } else if (IsPrimitive) { - var res = IsConvertibleToPrimitiveType(value, this); + object? res = IsConvertibleToPrimitiveType(value, this); if (res != null) return res; } else if (IsPointer) { - var vtype = value.GetType(); + Type? vtype = value.GetType(); if (vtype == typeof(IntPtr) || vtype == typeof(UIntPtr)) return value; if (value is Pointer pointer) @@ -2061,7 +2051,7 @@ private object TryConvertToType(object value, ref bool failed) // long value can be used with int based enum private static object IsConvertibleToPrimitiveType(object value, Type targetType) { - var type = value.GetType(); + Type? type = value.GetType(); if (type.IsEnum) { type = Enum.GetUnderlyingType(type); @@ -2069,8 +2059,8 @@ private static object IsConvertibleToPrimitiveType(object value, Type targetType return value; } - var from = GetTypeCode(type); - var to = GetTypeCode(targetType); + TypeCode from = GetTypeCode(type); + TypeCode to = GetTypeCode(targetType); switch (to) { @@ -2213,17 +2203,6 @@ private static object IsConvertibleToPrimitiveType(object value, Type targetType return null; } - private string GetCachedName(TypeNameKind kind) - { - switch (kind) - { - case TypeNameKind.SerializationName: - return ToString(); - default: - throw new NotImplementedException(); - } - } - [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern Type make_array_type(int rank); @@ -2302,7 +2281,7 @@ public override Type[] GetGenericParameterConstraints() internal static object CreateInstanceForAnotherGenericParameter(Type genericType, RuntimeType genericArgument) { var gt = (RuntimeType)MakeGenericType(genericType, new Type[] { genericArgument }); - var ctor = gt.GetDefaultConstructor(); + RuntimeConstructorInfo? ctor = gt.GetDefaultConstructor(); return ctor.InternalInvoke(null, null, wrapExceptions: true); } @@ -2318,7 +2297,7 @@ internal RuntimeMethodInfo[] GetMethodsByName(string name, BindingFlags bindingA using (var namePtr = new Mono.SafeStringMarshal(name)) using (var h = new Mono.SafeGPtrArrayHandle(GetMethodsByName_native(namePtr.Value, bindingAttr, listType))) { - var n = h.Length; + int n = h.Length; var a = new RuntimeMethodInfo[n]; for (int i = 0; i < n; i++) { @@ -2340,7 +2319,7 @@ private RuntimeConstructorInfo[] GetConstructors_internal(BindingFlags bindingAt var refh = new RuntimeTypeHandle(reflectedType); using (var h = new Mono.SafeGPtrArrayHandle(GetConstructors_native(bindingAttr))) { - var n = h.Length; + int n = h.Length; var a = new RuntimeConstructorInfo[n]; for (int i = 0; i < n; i++) { @@ -2357,7 +2336,7 @@ private RuntimePropertyInfo[] GetPropertiesByName(string name, BindingFlags bind using (var namePtr = new Mono.SafeStringMarshal(name)) using (var h = new Mono.SafeGPtrArrayHandle(GetPropertiesByName_native(namePtr.Value, bindingAttr, listType))) { - var n = h.Length; + int n = h.Length; var a = new RuntimePropertyInfo[n]; for (int i = 0; i < n; i++) { @@ -2373,7 +2352,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType) if (IsGenericParameter) throw new InvalidOperationException(Environment.GetResourceString("Arg_GenericParameter")); - if ((object)ifaceType == null) + if (ifaceType is null) throw new ArgumentNullException(nameof(ifaceType)); RuntimeType ifaceRtType = ifaceType as RuntimeType; @@ -2541,7 +2520,7 @@ private RuntimeType[] GetNestedTypes_internal(string displayName, BindingFlags b return null; string fullName; - var cache = Cache; + TypeCache? cache = Cache; if ((fullName = cache.full_name) == null) fullName = cache.full_name = getFullName(true, false); @@ -2569,7 +2548,7 @@ internal override bool IsUserType public override bool IsSubclassOf(Type type) { - if ((object)type == null) + if (type is null) throw new ArgumentNullException(nameof(type)); RuntimeType rtType = type as RuntimeType; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index 11d957c040e92..507a42854ffb6 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -314,7 +314,7 @@ internal static bool IsTypeDefinition(RuntimeType type) return (RuntimeType)a.GetType(typeName.Substring(0, idx), throwOnError, ignoreCase); } - var t = internal_from_name(typeName, ref stackMark, null, throwOnError, ignoreCase, false); + RuntimeType? t = internal_from_name(typeName, ref stackMark, null, throwOnError, ignoreCase, false); if (throwOnError && t == null) throw new TypeLoadException("Error loading '" + typeName + "'"); return t; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Security/DynamicSecurityMethodAttribute.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Security/DynamicSecurityMethodAttribute.cs index 9948485969669..140bfcf50e83b 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Security/DynamicSecurityMethodAttribute.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Security/DynamicSecurityMethodAttribute.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Runtime.InteropServices; - namespace System.Security { // DynamicSecurityMethodAttribute: diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/String.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/String.Mono.cs index 393efec176a24..93be899633586 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/String.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/String.Mono.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; -using Internal.Runtime.CompilerServices; namespace System { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Text/Utf8Span.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Text/Utf8Span.cs index f3b37c2e952d1..e13bfe7350e09 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Text/Utf8Span.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Text/Utf8Span.cs @@ -2,13 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Buffers; using System.ComponentModel; -using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Text.Unicode; -using Internal.Runtime.CompilerServices; #pragma warning disable 0809 //warning CS0809: Obsolete member 'Utf8Span.Equals(object)' overrides non-obsolete member 'object.Equals(object)' diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Unix.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Unix.Mono.cs index 7a776ee3232fd..1426b9ca14a03 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Unix.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Unix.Mono.cs @@ -88,7 +88,7 @@ private SafeWaitHandle ValidateHandle(out bool success) } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static unsafe extern IntPtr CreateEventInternal(bool manual, bool initialState, char* name, int name_length, out int errorCode); + private static extern unsafe IntPtr CreateEventInternal(bool manual, bool initialState, char* name, int name_length, out int errorCode); [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern bool ResetEventInternal(IntPtr handle); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.Mono.cs index cf664501d7e7f..5b1d59a46f8f8 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.Mono.cs @@ -6,7 +6,7 @@ namespace System.Threading { - internal unsafe sealed partial class LowLevelLifoSemaphore : IDisposable + internal sealed unsafe partial class LowLevelLifoSemaphore : IDisposable { private IntPtr lifo_semaphore; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Mutex.Unix.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Mutex.Unix.Mono.cs index c12d39928c2b1..b6174e93dab0f 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Mutex.Unix.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Mutex.Unix.Mono.cs @@ -68,10 +68,10 @@ private static unsafe IntPtr OpenMutex_internal(string name, out MonoIOError err } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static unsafe extern IntPtr CreateMutex_icall(bool initiallyOwned, char* name, int name_length, out bool created); + private static extern unsafe IntPtr CreateMutex_icall(bool initiallyOwned, char* name, int name_length, out bool created); [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static unsafe extern IntPtr OpenMutex_icall(char* name, int name_length, int rights, out MonoIOError error); + private static extern unsafe IntPtr OpenMutex_icall(char* name, int name_length, int rights, out MonoIOError error); [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern bool ReleaseMutex_internal(IntPtr handle); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Overlapped.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Overlapped.cs index ff37e273e4976..54a403e16646b 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Overlapped.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Overlapped.cs @@ -11,8 +11,8 @@ namespace System.Threading internal unsafe class _IOCompletionCallback { - private IOCompletionCallback _ioCompletionCallback; - private ExecutionContext _executionContext; + private readonly IOCompletionCallback _ioCompletionCallback; + private readonly ExecutionContext _executionContext; private uint _errorCode; // Error code private uint _numBytes; // No. of bytes transferred private NativeOverlapped* _pNativeOverlapped; @@ -65,7 +65,7 @@ internal static unsafe void PerformIOCompletionCallback(uint errorCode, uint num #region class OverlappedData - internal unsafe sealed class OverlappedData + internal sealed unsafe class OverlappedData { internal IAsyncResult _asyncResult; internal object _callback; // IOCompletionCallback or _IOCompletionCallback @@ -317,4 +317,4 @@ public static unsafe void Free(NativeOverlapped* nativeOverlappedPtr) } #endregion class Overlapped -} \ No newline at end of file +} diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Semaphore.Unix.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Semaphore.Unix.Mono.cs index c9f5b56240c82..a4d5d026ec405 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Semaphore.Unix.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Semaphore.Unix.Mono.cs @@ -94,10 +94,10 @@ private static unsafe IntPtr OpenSemaphore_internal(string name, int rights, out } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static unsafe extern IntPtr CreateSemaphore_icall(int initialCount, int maximumCount, char* name, int nameLength, out MonoIOError errorCode); + private static extern unsafe IntPtr CreateSemaphore_icall(int initialCount, int maximumCount, char* name, int nameLength, out MonoIOError errorCode); [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static unsafe extern IntPtr OpenSemaphore_icall(char* name, int nameLength, int rights, out MonoIOError errorCode); + private static extern unsafe IntPtr OpenSemaphore_icall(char* name, int nameLength, int rights, out MonoIOError errorCode); [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern bool ReleaseSemaphore_internal(IntPtr handle, int releaseCount, out int previousCount); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs index 9c1823323372f..6c8e336c3ef0c 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs @@ -100,7 +100,7 @@ public bool IsAlive { get { - var state = GetState(this); + ThreadState state = GetState(this); return (state & (ThreadState.Unstarted | ThreadState.Stopped | ThreadState.Aborted)) == 0; } } @@ -109,7 +109,7 @@ public bool IsBackground { get { - var state = ValidateThreadState(); + ThreadState state = ValidateThreadState(); return (state & ThreadState.Background) != 0; } set @@ -280,7 +280,7 @@ internal void StartCallback() else { var pdel = (ParameterizedThreadStart)m_start; - var arg = m_start_arg; + object? arg = m_start_arg; m_start = null; m_start_arg = null; pdel(arg); @@ -302,7 +302,7 @@ public static bool Yield() private ThreadState ValidateThreadState() { - var state = GetState(this); + ThreadState state = GetState(this); if ((state & ThreadState.Stopped) != 0) throw new ThreadStateException("Thread is dead; state can not be accessed."); return state; @@ -341,7 +341,7 @@ private static Thread InitializeCurrentThread() private static extern string GetName(Thread thread); [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static unsafe extern void SetName_icall(Thread thread, char* name, int nameLength); + private static extern unsafe void SetName_icall(Thread thread, char* name, int nameLength); private static unsafe void SetName(Thread thread, string name) { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/WaitHandle.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/WaitHandle.Mono.cs index b9ae29c95b2eb..82466de8ae990 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/WaitHandle.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/WaitHandle.Mono.cs @@ -10,7 +10,7 @@ namespace System.Threading public partial class WaitHandle { [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static unsafe extern int Wait_internal(IntPtr* handles, int numHandles, bool waitAll, int ms); + private static extern unsafe int Wait_internal(IntPtr* handles, int numHandles, bool waitAll, int ms); private static int WaitOneCore(IntPtr waitHandle, int millisecondsTimeout) { diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Type.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Type.Mono.cs index 67a34d1522660..606d79a806179 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Type.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Type.Mono.cs @@ -2,12 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Text; -using System.IO; using System.Reflection; -using System.Collections.Generic; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Threading; namespace System diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs b/src/mono/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs index 8448b0d82eb11..2f55edecfc67c 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs @@ -90,7 +90,7 @@ public override bool Equals(object? other) private class Display : ATypeName { - private string displayName; + private readonly string displayName; internal Display(string displayName) { @@ -134,7 +134,7 @@ internal static ITypeIdentifier WithoutEscape(string simpleName) private class Display : TypeNames.ATypeName, ITypeIdentifier { - private string displayName; + private readonly string displayName; private string internal_name; //cached internal Display(string displayName) @@ -171,7 +171,7 @@ public override ITypeName NestedName(ITypeIdentifier innerName) private class Internal : TypeNames.ATypeName, ITypeIdentifier { - private string internalName; + private readonly string internalName; private string display_name; //cached internal Internal(string internalName) @@ -213,7 +213,7 @@ public override ITypeName NestedName(ITypeIdentifier innerName) private class NoEscape : TypeNames.ATypeName, ITypeIdentifier { - private string simpleName; + private readonly string simpleName; internal NoEscape(string simpleName) { this.simpleName = simpleName; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/TypeNameParser.cs b/src/mono/netcore/System.Private.CoreLib/src/System/TypeNameParser.cs index ee37ec8b3ee7e..04a83e865ebb8 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/TypeNameParser.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/TypeNameParser.cs @@ -55,7 +55,7 @@ internal static class TypeNameParser } // Resolve base type - var type = ResolveType(assembly, pname.Names, typeResolver, throwOnError, ignoreCase, ref stackMark); + Type? type = ResolveType(assembly, pname.Names, typeResolver, throwOnError, ignoreCase, ref stackMark); if (type == null) return null; @@ -76,7 +76,7 @@ internal static class TypeNameParser if (pname.Modifiers != null) { bool bounded = false; - foreach (var mod in pname.Modifiers) + foreach (int mod in pname.Modifiers) { switch (mod) { @@ -130,7 +130,7 @@ internal static class TypeNameParser } else { - var assembly = assemblyResolver(aname); + Assembly? assembly = assemblyResolver(aname); if (assembly == null && throwOnError) throw new FileNotFoundException(SR.FileNotFound_ResolveAssembly, name); return assembly; @@ -378,7 +378,7 @@ private static ParsedName ParseName(string name, bool recursed, int pos, out int fqname = true; } - var arg = ParseName(name, true, pos, out pos); + ParsedName? arg = ParseName(name, true, pos, out pos); if (arg == null) return null; res.TypeArguments.Add(arg); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/TypeSpec.cs b/src/mono/netcore/System.Private.CoreLib/src/System/TypeSpec.cs index 15741baae22a4..755b0472f3000 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/TypeSpec.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/TypeSpec.cs @@ -42,8 +42,8 @@ internal interface IModifierSpec internal class IArraySpec : IModifierSpec { // dimensions == 1 and bound, or dimensions > 1 and !bound - private int dimensions; - private bool bound; + private readonly int dimensions; + private readonly bool bound; internal IArraySpec(int dimensions, bool bound) { @@ -93,7 +93,7 @@ public bool IsBound internal class PointerSpec : IModifierSpec { - private int pointer_level; + private readonly int pointer_level; internal PointerSpec(int pointer_level) { @@ -193,7 +193,7 @@ private string GetDisplayFullName(DisplayNameFormat flags) var sb = new Text.StringBuilder(name.DisplayName); if (nested != null) { - foreach (var n in nested) + foreach (ITypeIdentifier? n in nested) sb.Append('+').Append(n.DisplayName); } @@ -230,7 +230,7 @@ private Text.StringBuilder GetModifierString(Text.StringBuilder sb) { if (modifier_spec != null) { - foreach (var md in modifier_spec) + foreach (IModifierSpec? md in modifier_spec) md.Append(sb); } @@ -358,9 +358,9 @@ internal Type Resolve(Func assemblyResolver, Func assemblyResolver, Func assemblyResolver, Func