diff --git a/contributing.md b/contributing.md index bbf0a8b1..0954aa92 100644 --- a/contributing.md +++ b/contributing.md @@ -133,12 +133,12 @@ Example: #if !NET5_0_OR_GREATER +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Link = System.ComponentModel.DescriptionAttribute; -namespace System.Runtime.CompilerServices; - /// /// Used to indicate to the compiler that a method should be called /// in its containing module's initializer. diff --git a/src/Polyfill/CallerArgumentExpressionAttribute.cs b/src/Polyfill/CallerArgumentExpressionAttribute.cs index bf174414..34eaf643 100644 --- a/src/Polyfill/CallerArgumentExpressionAttribute.cs +++ b/src/Polyfill/CallerArgumentExpressionAttribute.cs @@ -2,12 +2,12 @@ #if NETFRAMEWORK || NETSTANDARD || NETCOREAPP2X +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Link = System.ComponentModel.DescriptionAttribute; -namespace System.Runtime.CompilerServices; - /// /// Indicates that a parameter captures the expression passed for another parameter as a string. /// diff --git a/src/Polyfill/CompilerFeatureRequiredAttribute.cs b/src/Polyfill/CompilerFeatureRequiredAttribute.cs index 9d39b5fe..28fb64c7 100644 --- a/src/Polyfill/CompilerFeatureRequiredAttribute.cs +++ b/src/Polyfill/CompilerFeatureRequiredAttribute.cs @@ -2,12 +2,12 @@ #if !NET7_0_OR_GREATER +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Link = System.ComponentModel.DescriptionAttribute; -namespace System.Runtime.CompilerServices; - /// /// Indicates that compiler support for a particular feature is required for the location where this attribute is applied. /// diff --git a/src/Polyfill/DisableRuntimeMarshallingAttribute.cs b/src/Polyfill/DisableRuntimeMarshallingAttribute.cs index 4d611658..34b36cbd 100644 --- a/src/Polyfill/DisableRuntimeMarshallingAttribute.cs +++ b/src/Polyfill/DisableRuntimeMarshallingAttribute.cs @@ -2,12 +2,12 @@ #if !NET7_0_OR_GREATER +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Link = System.ComponentModel.DescriptionAttribute; -namespace System.Runtime.CompilerServices; - /// /// Disables the built-in runtime managed/unmanaged marshalling subsystem for /// P/Invokes, Delegate types, and unmanaged function pointer invocations. diff --git a/src/Polyfill/ExperimentalAttribute.cs b/src/Polyfill/ExperimentalAttribute.cs index ec549f38..87cd4376 100644 --- a/src/Polyfill/ExperimentalAttribute.cs +++ b/src/Polyfill/ExperimentalAttribute.cs @@ -4,12 +4,12 @@ #if !NET8_0_OR_GREATER +namespace System.Diagnostics.CodeAnalysis; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Link = System.ComponentModel.DescriptionAttribute; -namespace System.Diagnostics.CodeAnalysis; - /// /// Indicates that a parameter captures the expression passed for another parameter as a string. /// diff --git a/src/Polyfill/IndexRange/Index.cs b/src/Polyfill/IndexRange/Index.cs index 478e9dbe..51910924 100644 --- a/src/Polyfill/IndexRange/Index.cs +++ b/src/Polyfill/IndexRange/Index.cs @@ -2,12 +2,12 @@ #if (NET46X && VALUETUPLEREFERENCED) || NET47X || NET48X || NETSTANDARD2_0 || NETCOREAPP2X +namespace System; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace System; - /// Represent a type can be used to index a collection either from the start or the end. /// /// Index is used by the C# compiler to support the new index syntax diff --git a/src/Polyfill/IndexRange/Range.cs b/src/Polyfill/IndexRange/Range.cs index 30f30909..1c59e07d 100644 --- a/src/Polyfill/IndexRange/Range.cs +++ b/src/Polyfill/IndexRange/Range.cs @@ -2,12 +2,12 @@ #if (NET46X && VALUETUPLEREFERENCED) || NET47X || NET48X || NETSTANDARD2_0 || NETCOREAPP2X +namespace System; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -namespace System; - /// Represent a range has start and end indexes. /// /// Range is used by the C# compiler to support the range syntax. diff --git a/src/Polyfill/IsExternalInit.cs b/src/Polyfill/IsExternalInit.cs index ee40249e..35a7e7c4 100644 --- a/src/Polyfill/IsExternalInit.cs +++ b/src/Polyfill/IsExternalInit.cs @@ -2,11 +2,11 @@ #if !NET5_0_OR_GREATER +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.CompilerServices; - /// /// Reserved to be used by the compiler for tracking metadata. This class should not be used by developers in source code. /// diff --git a/src/Polyfill/ModuleInitializerAttribute.cs b/src/Polyfill/ModuleInitializerAttribute.cs index 7889a399..df30f2d3 100644 --- a/src/Polyfill/ModuleInitializerAttribute.cs +++ b/src/Polyfill/ModuleInitializerAttribute.cs @@ -2,12 +2,12 @@ #if !NET5_0_OR_GREATER +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Link = System.ComponentModel.DescriptionAttribute; -namespace System.Runtime.CompilerServices; - /// /// Used to indicate to the compiler that a method should be called /// in its containing module's initializer. diff --git a/src/Polyfill/Nullability/NullabilityInfo.cs b/src/Polyfill/Nullability/NullabilityInfo.cs index 5fc4d8b5..54888271 100644 --- a/src/Polyfill/Nullability/NullabilityInfo.cs +++ b/src/Polyfill/Nullability/NullabilityInfo.cs @@ -14,6 +14,12 @@ namespace System.Reflection { + using System.Linq; + using System.Diagnostics.CodeAnalysis; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + /// /// A class that represents nullability info /// diff --git a/src/Polyfill/Nullability/NullabilityInfoContext.cs b/src/Polyfill/Nullability/NullabilityInfoContext.cs index 4ac7d429..764bdbed 100644 --- a/src/Polyfill/Nullability/NullabilityInfoContext.cs +++ b/src/Polyfill/Nullability/NullabilityInfoContext.cs @@ -16,9 +16,11 @@ namespace System.Reflection { - // Some codebases define their own Debug class, which can cause clashes and compile errors if we aren't explicit here. - // See comments in Debug.cs in Consume project for more details. - using Debug = System.Diagnostics.Debug; + using System.Linq; + using System.Diagnostics.CodeAnalysis; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; /// /// Provides APIs for populating nullability information/context from reflection members: diff --git a/src/Polyfill/PlatformCompatibility/OSPlatformAttribute.cs b/src/Polyfill/PlatformCompatibility/OSPlatformAttribute.cs index e3b722b1..048f7421 100644 --- a/src/Polyfill/PlatformCompatibility/OSPlatformAttribute.cs +++ b/src/Polyfill/PlatformCompatibility/OSPlatformAttribute.cs @@ -4,11 +4,11 @@ #pragma warning disable +namespace System.Runtime.Versioning; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.Versioning; - /// /// Base type for all platform-specific API attributes. /// diff --git a/src/Polyfill/PlatformCompatibility/ObsoletedOSPlatformAttribute.cs b/src/Polyfill/PlatformCompatibility/ObsoletedOSPlatformAttribute.cs index 942411dc..2854ca96 100644 --- a/src/Polyfill/PlatformCompatibility/ObsoletedOSPlatformAttribute.cs +++ b/src/Polyfill/PlatformCompatibility/ObsoletedOSPlatformAttribute.cs @@ -4,13 +4,13 @@ #pragma warning disable -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - #nullable enable namespace System.Runtime.Versioning; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + using Targets = AttributeTargets; /// diff --git a/src/Polyfill/PlatformCompatibility/SupportedOSPlatformAttribute.cs b/src/Polyfill/PlatformCompatibility/SupportedOSPlatformAttribute.cs index e1885da6..11655f12 100644 --- a/src/Polyfill/PlatformCompatibility/SupportedOSPlatformAttribute.cs +++ b/src/Polyfill/PlatformCompatibility/SupportedOSPlatformAttribute.cs @@ -4,11 +4,11 @@ #pragma warning disable +namespace System.Runtime.Versioning; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.Versioning; - using Targets = AttributeTargets; /// diff --git a/src/Polyfill/PlatformCompatibility/SupportedOSPlatformGuardAttribute.cs b/src/Polyfill/PlatformCompatibility/SupportedOSPlatformGuardAttribute.cs index 13333f8d..f8d109e1 100644 --- a/src/Polyfill/PlatformCompatibility/SupportedOSPlatformGuardAttribute.cs +++ b/src/Polyfill/PlatformCompatibility/SupportedOSPlatformGuardAttribute.cs @@ -4,11 +4,11 @@ #pragma warning disable +namespace System.Runtime.Versioning; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.Versioning; - using Targets = AttributeTargets; /// diff --git a/src/Polyfill/PlatformCompatibility/TargetPlatformAttribute.cs b/src/Polyfill/PlatformCompatibility/TargetPlatformAttribute.cs index 26e192c1..d340b45c 100644 --- a/src/Polyfill/PlatformCompatibility/TargetPlatformAttribute.cs +++ b/src/Polyfill/PlatformCompatibility/TargetPlatformAttribute.cs @@ -2,11 +2,11 @@ #if !NET5_0_OR_GREATER +namespace System.Runtime.Versioning; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.Versioning; - /// /// Records the platform that the project targeted. /// diff --git a/src/Polyfill/PlatformCompatibility/UnsupportedOSPlatformAttribute.cs b/src/Polyfill/PlatformCompatibility/UnsupportedOSPlatformAttribute.cs index 6af9ea69..ffc26bef 100644 --- a/src/Polyfill/PlatformCompatibility/UnsupportedOSPlatformAttribute.cs +++ b/src/Polyfill/PlatformCompatibility/UnsupportedOSPlatformAttribute.cs @@ -4,11 +4,11 @@ #nullable enable +namespace System.Runtime.Versioning; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.Versioning; - using Targets = AttributeTargets; /// diff --git a/src/Polyfill/PlatformCompatibility/UnsupportedOSPlatformGuardAttribute.cs b/src/Polyfill/PlatformCompatibility/UnsupportedOSPlatformGuardAttribute.cs index aa446f86..21835579 100644 --- a/src/Polyfill/PlatformCompatibility/UnsupportedOSPlatformGuardAttribute.cs +++ b/src/Polyfill/PlatformCompatibility/UnsupportedOSPlatformGuardAttribute.cs @@ -4,11 +4,11 @@ #pragma warning disable +namespace System.Runtime.Versioning; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.Versioning; - using Targets = AttributeTargets; /// diff --git a/src/Polyfill/RequiredMemberAttribute.cs b/src/Polyfill/RequiredMemberAttribute.cs index 3b245bf0..144e1218 100644 --- a/src/Polyfill/RequiredMemberAttribute.cs +++ b/src/Polyfill/RequiredMemberAttribute.cs @@ -2,11 +2,11 @@ #if !NET7_0_OR_GREATER +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.CompilerServices; - using Targets = AttributeTargets; /// diff --git a/src/Polyfill/SkipLocalsInitAttribute.cs b/src/Polyfill/SkipLocalsInitAttribute.cs index df042fb1..7f64aa8b 100644 --- a/src/Polyfill/SkipLocalsInitAttribute.cs +++ b/src/Polyfill/SkipLocalsInitAttribute.cs @@ -2,11 +2,11 @@ #if !NET5_0_OR_GREATER +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.CompilerServices; - using Targets = AttributeTargets; /// diff --git a/src/Polyfill/StackTraceHiddenAttribute.cs b/src/Polyfill/StackTraceHiddenAttribute.cs index 2634e040..028b9bab 100644 --- a/src/Polyfill/StackTraceHiddenAttribute.cs +++ b/src/Polyfill/StackTraceHiddenAttribute.cs @@ -2,10 +2,10 @@ #if !NET6_0_OR_GREATER -using System.Diagnostics.CodeAnalysis; - namespace System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + using Targets = AttributeTargets; /// diff --git a/src/Polyfill/StringInterpolation/AppendInterpolatedStringHandler.cs b/src/Polyfill/StringInterpolation/AppendInterpolatedStringHandler.cs index 574923bf..d088b3c0 100644 --- a/src/Polyfill/StringInterpolation/AppendInterpolatedStringHandler.cs +++ b/src/Polyfill/StringInterpolation/AppendInterpolatedStringHandler.cs @@ -2,17 +2,13 @@ #if HAS_SPAN && !NET6_0_OR_GREATER -using System.ComponentModel; -using System.Diagnostics; -using System.Runtime.CompilerServices; - #nullable enable namespace System.Text; -// Some codebases define their own Debug class, which can cause clashes and compile errors if we aren't explicit here. -// See comments in Debug.cs in Consume project for more details. -using Debug = System.Diagnostics.Debug; +using System.ComponentModel; +using System.Diagnostics; +using System.Runtime.CompilerServices; /// Provides a handler used by the language compiler to append interpolated strings into instances. [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Polyfill/StringInterpolation/DefaultInterpolatedStringHandler.cs b/src/Polyfill/StringInterpolation/DefaultInterpolatedStringHandler.cs index 2850af42..b15eec55 100644 --- a/src/Polyfill/StringInterpolation/DefaultInterpolatedStringHandler.cs +++ b/src/Polyfill/StringInterpolation/DefaultInterpolatedStringHandler.cs @@ -2,6 +2,10 @@ #if HAS_SPAN && !NET6_0_OR_GREATER +#nullable enable + +namespace System.Runtime.CompilerServices; + using System; using System.Buffers; using System.Diagnostics; @@ -10,14 +14,6 @@ using System.Runtime.CompilerServices; using Link = System.ComponentModel.DescriptionAttribute; -#nullable enable - -namespace System.Runtime.CompilerServices; - -// Some codebases define their own Debug class, which can cause clashes and compile errors if we aren't explicit here. -// See comments in Debug.cs in Consume project for more details. -using Debug = System.Diagnostics.Debug; - /// Provides a handler used by the language compiler to process interpolated strings into instances. [InterpolatedStringHandler] [ExcludeFromCodeCoverage] diff --git a/src/Polyfill/StringInterpolation/InterpolatedStringHandlerArgumentAttribute.cs b/src/Polyfill/StringInterpolation/InterpolatedStringHandlerArgumentAttribute.cs index c2ab3559..04ee127e 100644 --- a/src/Polyfill/StringInterpolation/InterpolatedStringHandlerArgumentAttribute.cs +++ b/src/Polyfill/StringInterpolation/InterpolatedStringHandlerArgumentAttribute.cs @@ -2,12 +2,12 @@ #if !NET6_0_OR_GREATER +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Link = System.ComponentModel.DescriptionAttribute; -namespace System.Runtime.CompilerServices; - /// /// Indicates which arguments to a method involving an interpolated string handler should be passed to that handler. /// diff --git a/src/Polyfill/StringInterpolation/InterpolatedStringHandlerAttribute.cs b/src/Polyfill/StringInterpolation/InterpolatedStringHandlerAttribute.cs index 4486b5dc..23b0b661 100644 --- a/src/Polyfill/StringInterpolation/InterpolatedStringHandlerAttribute.cs +++ b/src/Polyfill/StringInterpolation/InterpolatedStringHandlerAttribute.cs @@ -2,12 +2,12 @@ #if !NET6_0_OR_GREATER +namespace System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Link = System.ComponentModel.DescriptionAttribute; -namespace System.Runtime.CompilerServices; - using Targets = AttributeTargets; /// diff --git a/src/Polyfill/StringSyntaxAttribute.cs b/src/Polyfill/StringSyntaxAttribute.cs index feeda19d..f773986f 100644 --- a/src/Polyfill/StringSyntaxAttribute.cs +++ b/src/Polyfill/StringSyntaxAttribute.cs @@ -4,11 +4,11 @@ #nullable enable +namespace System.Diagnostics.CodeAnalysis; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Diagnostics.CodeAnalysis; - using Targets = AttributeTargets; /// diff --git a/src/Polyfill/SuppressGCTransitionAttribute.cs b/src/Polyfill/SuppressGCTransitionAttribute.cs index b64687d3..2ae81cfb 100644 --- a/src/Polyfill/SuppressGCTransitionAttribute.cs +++ b/src/Polyfill/SuppressGCTransitionAttribute.cs @@ -2,11 +2,11 @@ #if !NET5_0_OR_GREATER +namespace System.Runtime.InteropServices; + using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -namespace System.Runtime.InteropServices; - /// /// An attribute used to indicate a GC transition should be skipped when making an unmanaged function call. /// diff --git a/src/Polyfill/UnmanagedCallersOnlyAttribute.cs b/src/Polyfill/UnmanagedCallersOnlyAttribute.cs index 6b8a09db..b8856808 100644 --- a/src/Polyfill/UnmanagedCallersOnlyAttribute.cs +++ b/src/Polyfill/UnmanagedCallersOnlyAttribute.cs @@ -4,14 +4,13 @@ #nullable enable - -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - #pragma warning disable CS0649 namespace System.Runtime.InteropServices; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + /// /// Any method marked with can be directly called from /// native code. The function token can be loaded to a local variable using the address-of operator diff --git a/src/Polyfill/UnreachableException.cs b/src/Polyfill/UnreachableException.cs index 0de4e6ca..7c03178a 100644 --- a/src/Polyfill/UnreachableException.cs +++ b/src/Polyfill/UnreachableException.cs @@ -4,13 +4,13 @@ #nullable enable +namespace System.Diagnostics; + using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text; -namespace System.Diagnostics; - /// /// Exception thrown when the program executes an instruction that was thought to be unreachable. /// diff --git a/src/Polyfill/UnscopedRefAttribute.cs b/src/Polyfill/UnscopedRefAttribute.cs index f8c3134d..a61ed71f 100644 --- a/src/Polyfill/UnscopedRefAttribute.cs +++ b/src/Polyfill/UnscopedRefAttribute.cs @@ -2,10 +2,10 @@ #if !NET7_0_OR_GREATER -using System.Diagnostics; - namespace System.Diagnostics.CodeAnalysis; +using System.Diagnostics; + using Targets = AttributeTargets; /// diff --git a/src/Tests/NullabilitySync.cs b/src/Tests/NullabilitySync.cs index 569e6ab8..09f12ad1 100644 --- a/src/Tests/NullabilitySync.cs +++ b/src/Tests/NullabilitySync.cs @@ -66,6 +66,7 @@ public async Task Run() info = prefix + info + suffix; info = MakeInternal(info); + info = AddDebugClassFix(info); OverWrite(info, "NullabilityInfo.cs"); } @@ -89,18 +90,23 @@ static string MakeInternal(string source) => sealed class """); - static string AddDebugClassFix(string source) => - source - .Replace( - "namespace System.Reflection\r\n{", - """ - namespace System.Reflection - { - // Some codebases define their own Debug class, which can cause clashes and compile errors if we aren't explicit here. - // See comments in Debug.cs in Consume project for more details. - using Debug = System.Diagnostics.Debug; - - """); + static string AddDebugClassFix(string source) + { + var newValue = """ + namespace System.Reflection + { + using System.Linq; + using System.Diagnostics.CodeAnalysis; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + + """; + return source + .Replace("namespace System.Reflection\r\n{", newValue) + .Replace("namespace System.Reflection\n{", newValue) + .Replace("namespace System.Reflection\r{", newValue); + } static void OverWrite(string content, string file) {