Skip to content

Commit

Permalink
Replace NETCOREAPP compiler directive with NET (dotnet#101693)
Browse files Browse the repository at this point in the history
* Replace NETCOREAPP compiler directive with NET

Consistently use the `NET` preprocessor directive
instead of a mix of both `NETCOREAPP` and `NET`.

* Remaining NETCOREAPP usages

* Update TestCaseCompilationMetadataProvider.cs

* Update TestCaseCompilationMetadataProvider.cs
  • Loading branch information
ViktorHofer authored and michaelgsharp committed May 8, 2024
1 parent b328911 commit 07fac98
Show file tree
Hide file tree
Showing 423 changed files with 853 additions and 853 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected virtual void SetupProcess (Process process, CompilerOptions options)
private static string BuildArguments (CompilerOptions options)
{
var args = new StringBuilder ();
#if NETCOREAPP
#if NET
args.Append (options.OutputPath.ExtensionWithDot == ".dll" ? "-dll" : "-exe");
args.Append ($" -out:{options.OutputPath.InQuotes ()}");
#else
Expand All @@ -58,7 +58,7 @@ private static string BuildArguments (CompilerOptions options)

protected virtual NPath LocateIlasm ()
{
#if NETCOREAPP
#if NET
var extension = RuntimeInformation.IsOSPlatform (OSPlatform.Windows) ? ".exe" : "";

var toolsDir = (string) AppContext.GetData ("Mono.Linker.Tests.ILToolsDir")!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public virtual IEnumerable<string> GetDefines ()
yield return "WIN32";

if (Characteristics.HasFlag (TestRunCharacteristics.TargetingNetCore))
yield return "NETCOREAPP";
yield return "NET";

if (Characteristics.HasFlag (TestRunCharacteristics.SupportsDefaultInterfaceMethods))
yield return "SUPPORTS_DEFAULT_INTERFACE_METHODS";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Text;
using Mono.Linker.Tests.Extensions;
using Xunit;
#if NETCOREAPP
#if NET
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Emit;
Expand Down Expand Up @@ -190,7 +190,7 @@ protected static NPath MakeSupportingAssemblyReferencePathAbsolute (NPath output
if (Path.IsPathRooted (referenceFileName))
return referenceFileName.ToNPath ();

#if NETCOREAPP
#if NET
if (referenceFileName.StartsWith ("System.", StringComparison.Ordinal) ||
referenceFileName.StartsWith ("Mono.", StringComparison.Ordinal) ||
referenceFileName.StartsWith ("Microsoft.", StringComparison.Ordinal) ||
Expand Down Expand Up @@ -224,14 +224,14 @@ protected NPath CompileAssembly (CompilerOptions options)

protected virtual NPath CompileCSharpAssemblyWithDefaultCompiler (CompilerOptions options)
{
#if NETCOREAPP
#if NET
return CompileCSharpAssemblyWithRoslyn (options);
#else
return CompileCSharpAssemblyWithCsc (options);
#endif
}

#if NETCOREAPP
#if NET
protected virtual NPath CompileCSharpAssemblyWithRoslyn (CompilerOptions options)
{
var languageVersion = LanguageVersion.Default;
Expand Down Expand Up @@ -331,7 +331,7 @@ protected virtual NPath CompileCSharpAssemblyWithRoslyn (CompilerOptions options

protected virtual NPath CompileCSharpAssemblyWithCsc (CompilerOptions options)
{
#if NETCOREAPP
#if NET
return CompileCSharpAssemblyWithRoslyn (options);
#else
return CompileCSharpAssemblyWithExternalCompiler (LocateCscExecutable (), options, "/shared ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public virtual void ProcessOptions (TestCaseLinkerOptions options)

IgnoreLinkAttributes (options.IgnoreLinkAttributes);

#if !NETCOREAPP
#if !NET
if (!string.IsNullOrEmpty (options.Il8n))
AddIl8n (options.Il8n);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static class ChangeCallbackRegistrar
/// <returns>The <see cref="CancellationToken"/> registration.</returns>
internal static IDisposable UnsafeRegisterChangeCallback<T>(Action<object?> callback, object? state, CancellationToken token, Action<T> onFailure, T onFailureState)
{
#if NETCOREAPP || NETSTANDARD2_1
#if NET || NETSTANDARD2_1
try
{
return token.UnsafeRegister(callback, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal static unsafe ErrorCode NCryptGetIntProperty(SafeNCryptHandle hObject,
{
fixed (int* pResult = &result)
{
#if NETSTANDARD || NETCOREAPP
#if NETSTANDARD || NET
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/HashCodeRandomization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class HashCodeRandomization
{
public static int GetRandomizedOrdinalHashCode(this string value)
{
#if NETCOREAPP
#if NET
// In .NET Core, string hash codes are already randomized.

return value.GetHashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static void AppendQuoted(this ref ValueStringBuilder vsb, string s)
vsb.Append(quoteChar);
}

#if !NETCOREAPP
#if !NET
private static void AppendSpanFormattable(this ref ValueStringBuilder vsb, ushort value)
{
vsb.Append(value.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ private static ResourceTypeCode FindTypeCode(object? value, List<string> types)
if (typeName.StartsWith("ResourceTypeCode.", StringComparison.Ordinal))
{
typeName = typeName.Substring(17); // Remove through '.'
#if NETCOREAPP
#if NET
ResourceTypeCode typeCode = Enum.Parse<ResourceTypeCode>(typeName);
#else
ResourceTypeCode typeCode = (ResourceTypeCode)Enum.Parse(typeof(ResourceTypeCode), typeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal bool VerifyMac(
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
}

#if NETCOREAPP
#if NET
Debug.Assert(expectedOutputSize <= 64); // SHA512 is the largest digest size we know about
Span<byte> derived = stackalloc byte[expectedOutputSize];
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal static void Return(byte[] array, int clearSize = ClearAll)

if (!clearWholeArray && clearSize != 0)
{
#if (NETCOREAPP || NETSTANDARD2_1) && !CP_NO_ZEROMEMORY
#if (NET || NETSTANDARD2_1) && !CP_NO_ZEROMEMORY
CryptographicOperations.ZeroMemory(array.AsSpan(0, clearSize));
#else
Array.Clear(array, 0, clearSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ internal static partial class Helpers
{
[UnsupportedOSPlatformGuard("browser")]
internal static bool HasSymmetricEncryption { get; } =
#if NETCOREAPP
#if NET
!OperatingSystem.IsBrowser();
#else
true;
#endif

#if NETCOREAPP
#if NET
[UnsupportedOSPlatformGuard("ios")]
[UnsupportedOSPlatformGuard("tvos")]
public static bool IsDSASupported => !OperatingSystem.IsIOS() && !OperatingSystem.IsTvOS();
#else
public static bool IsDSASupported => true;
#endif

#if NETCOREAPP
#if NET
[UnsupportedOSPlatformGuard("android")]
[UnsupportedOSPlatformGuard("browser")]
public static bool IsRC2Supported => !OperatingSystem.IsAndroid() && !OperatingSystem.IsBrowser();
Expand All @@ -36,7 +36,7 @@ internal static partial class Helpers

[UnsupportedOSPlatformGuard("browser")]
internal static bool HasMD5 { get; } =
#if NETCOREAPP
#if NET
!OperatingSystem.IsBrowser();
#else
true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal sealed class PooledByteBufferWriter : IBufferWriter<byte>, IDisposable

private PooledByteBufferWriter()
{
#if NETCOREAPP
#if NET
// Ensure we are in sync with the Array.MaxLength implementation.
Debug.Assert(MaximumBufferSize == Array.MaxLength);
#endif
Expand Down Expand Up @@ -147,7 +147,7 @@ public Span<byte> GetSpan(int sizeHint = MinimumBufferSize)
return _rentedBuffer.AsSpan(_index);
}

#if NETCOREAPP
#if NET
internal ValueTask WriteToStreamAsync(Stream destination, CancellationToken cancellationToken)
{
return destination.WriteAsync(WrittenMemory, cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Text/ValueStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void Insert(int index, string? s)
int remaining = _pos - index;
_chars.Slice(index, remaining).CopyTo(_chars.Slice(index + count));
s
#if !NETCOREAPP
#if !NET
.AsSpan()
#endif
.CopyTo(_chars.Slice(index));
Expand Down Expand Up @@ -213,7 +213,7 @@ private void AppendSlow(string s)
}

s
#if !NETCOREAPP
#if !NET
.AsSpan()
#endif
.CopyTo(_chars.Slice(pos));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private static async Task<Document> RecreateDocumentAsync(Document document)
}

private static string ReplaceLineEndings(string text) =>
#if NETCOREAPP
#if NET
text.ReplaceLineEndings("\n");
#else
text.Replace("\r\n", "\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ protected IEnumerable<T> CreateHashSet(IEnumerable<T> enumerableToMatchTo, int c
return set;
}

#if NETCOREAPP
#if NET
/// <summary>
/// Create a HashSet with a specific initial capacity and fill it with a specific number of elements.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static void IsZipSameAsDir(Stream archiveFile, string directory, ZipArchi
using (Stream entrystream = entry.Open())
{
ReadAllBytes(entrystream, buffer, 0, buffer.Length);
#if NETCOREAPP
#if NET
uint zipcrc = entry.Crc32;
Assert.Equal(CRC.CalculateCRC(buffer), zipcrc);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ByteAtATimeContent(int length, Task waitToSend, TaskCompletionSource<bool
_millisecondDelayBetweenBytes = millisecondDelayBetweenBytes;
}

#if NETCOREAPP
#if NET
protected override void SerializeToStream(Stream stream, TransportContext context, CancellationToken cancellationToken) =>
SerializeToStreamAsync(stream, context).GetAwaiter().GetResult();
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ await server.AcceptConnectionAsync(async connection =>
}

[Theory]
#if NETCOREAPP
#if NET
[InlineData(DecompressionMethods.Brotli, "br", "")]
[InlineData(DecompressionMethods.Brotli, "br", "br")]
[InlineData(DecompressionMethods.Brotli, "br", "gzip")]
Expand Down Expand Up @@ -264,7 +264,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) =>
}

[Theory]
#if NETCOREAPP
#if NET
[InlineData(DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli, "gzip; q=1.0, deflate; q=1.0, br; q=1.0", "")]
#endif
[InlineData(DecompressionMethods.GZip | DecompressionMethods.Deflate, "gzip; q=1.0, deflate; q=1.0", "")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
#if !NETCOREAPP
#if !NET
using System.Diagnostics;
#endif
using System.IO;
Expand Down Expand Up @@ -90,7 +90,7 @@ public VersionCheckerHttpHandler(HttpMessageHandler innerHandler, Version expect
_expectedVersion = expectedVersion;
}

#if NETCOREAPP
#if NET
protected override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Version != _expectedVersion)
Expand Down Expand Up @@ -138,7 +138,7 @@ public static Task<HttpResponseMessage> SendAsync(this HttpClient client, bool a
}
else
{
#if NETCOREAPP
#if NET
// Note that the sync call must be done on a different thread because it blocks until the server replies.
// However, the server-side of the request handling is in many cases invoked after the client, thus deadlocking the test.
return Task.Run(() => client.Send(request, completionOption, cancellationToken));
Expand All @@ -159,7 +159,7 @@ public static Task<HttpResponseMessage> SendAsync(this HttpMessageInvoker invoke
}
else
{
#if NETCOREAPP
#if NET
// Note that the sync call must be done on a different thread because it blocks until the server replies.
// However, the server-side of the request handling is in many cases invoked after the client, thus deadlocking the test.
return Task.Run(() => invoker.Send(request, cancellationToken));
Expand All @@ -176,7 +176,7 @@ public static Task<Stream> ReadAsStreamAsync(this HttpContent content, bool asyn
{
if (async)
{
#if NETCOREAPP
#if NET
// No CancellationToken accepting overload on NETFX.
return content.ReadAsStreamAsync(cancellationToken);
#else
Expand All @@ -186,7 +186,7 @@ public static Task<Stream> ReadAsStreamAsync(this HttpContent content, bool asyn
}
else
{
#if NETCOREAPP
#if NET
return Task.FromResult(content.ReadAsStream(cancellationToken));
#else
// Framework won't ever have the sync API.
Expand All @@ -199,7 +199,7 @@ public static Task<Stream> ReadAsStreamAsync(this HttpContent content, bool asyn

public static Task<byte[]> GetByteArrayAsync(this HttpClient client, bool async, bool useCopyTo, Uri uri)
{
#if NETCOREAPP
#if NET
return Task.Run(async () =>
{
var m = new HttpRequestMessage(HttpMethod.Get, uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public LoopbackServerHttpMessageHandler(Func<HttpMessageHandlerLoopbackServer, T
_serverFunc = serverFunc;
}

#if NETCOREAPP
#if NET
protected override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
{
return SendAsync(request, cancellationToken).GetAwaiter().GetResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ await client.GetAsync(remoteServer.EchoUri, HttpCompletionOption.ResponseHeaders
}
}

#if NETCOREAPP
#if NET

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsChromium))]
public async Task BrowserHttpHandler_Streaming()
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/tests/System/Net/Http/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static Task WhenAllCompletedOrAnyFailedWithTimeout(int timeoutInMilliseco
return TaskTimeoutExtensions.WhenAllOrAnyFailed(tasks, timeoutInMilliseconds);
}

#if NETCOREAPP
#if NET
public static Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> AllowAllCertificates = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
#else
public static Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> AllowAllCertificates = (_, __, ___, ____) => true;
Expand Down Expand Up @@ -149,7 +149,7 @@ public static X509Certificate2 CreateServerSelfSignedCertificate(string name = "
}
}

#if NETCOREAPP
#if NET
public static SocketsHttpHandler CreateSocketsHttpHandler(bool allowAllCertificates = false)
{
var handler = new SocketsHttpHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void InvalidArrayArguments_Throws()
}
}

#if NETCOREAPP
#if NET
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Not supported on Browser/iOS/tvOS/MacCatalyst")]
public sealed class DSASignVerify_Span : DSASignVerify
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace System.Security.Cryptography.Tests
{
public class CurveDef
{
#if NETCOREAPP
#if NET
public CurveDef() { }
public ECCurve Curve;
public ECCurve.ECCurveType CurveType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace System.Security.Cryptography.Tests
/// </summary>
public abstract class EccTestBase
{
#if NETCOREAPP
#if NET
internal const string ECDSA_P224_OID_VALUE = "1.3.132.0.33"; // Also called nistP224 or secP224r1
internal const string ECDSA_P256_OID_VALUE = "1.2.840.10045.3.1.7"; // Also called nistP256, secP256r1 or prime256v1(OpenSsl)
internal const string ECDSA_P384_OID_VALUE = "1.3.132.0.34"; // Also called nistP384 or secP384r1
Expand Down
Loading

0 comments on commit 07fac98

Please sign in to comment.