Skip to content

Commit

Permalink
Replace usage of out-of-support TFM compiler directives (dotnet#101672)
Browse files Browse the repository at this point in the history
* Replace usage of out-of-support TFM compiler directives

... and directives for TFMs that we don't target anymore in main.

Replaces the following directives with `NET` or `!NET`:
- `#if NETCOREAPP2*`
- `#if !NETCOREAPP2*`
- `#if NETCOREAPP3*`
- `#if !NETCOREAPP3*`
- `#if NET5*`
- `#if !NET5*`
- `#if NET6*`
- `#if !NET6*`
- `#if NET7*`
- `#if !NET7*`

* Update EmitterTests.cs
  • Loading branch information
ViktorHofer authored Apr 29, 2024
1 parent 4ac82c9 commit 2616119
Show file tree
Hide file tree
Showing 128 changed files with 253 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public TValue AddOrGetExisting(TValue value)

private TValue AddOrGetExistingInner(TValue value, out bool addedValue)
{
#if NET5_0_OR_GREATER
#if NET
ArgumentNullException.ThrowIfNull(value);
#else
if (value == null)
Expand Down Expand Up @@ -596,7 +596,7 @@ public bool Contains(TKey key)
/// <returns>Value from the hashtable if found, otherwise null.</returns>
public TValue GetValueIfExists(TValue value)
{
#if NET5_0_OR_GREATER
#if NET
ArgumentNullException.ThrowIfNull(value);
#else
if (value == null)
Expand Down
14 changes: 7 additions & 7 deletions src/libraries/Common/src/Interop/Interop.Ldap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif
using System.Security.Authentication;
Expand All @@ -31,7 +31,7 @@ internal readonly struct Luid
public int HighPart => _highPart;
}

#if NET7_0_OR_GREATER
#if NET
[NativeMarshalling(typeof(Marshaller))]
#endif
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
Expand All @@ -49,7 +49,7 @@ internal struct SEC_WINNT_AUTH_IDENTITY_EX
public string packageList;
public int packageListLength;

#if NET7_0_OR_GREATER
#if NET
[CustomMarshaller(typeof(SEC_WINNT_AUTH_IDENTITY_EX), MarshalMode.ManagedToUnmanagedIn, typeof(Marshaller))]
internal static class Marshaller
{
Expand Down Expand Up @@ -176,7 +176,7 @@ internal struct LDAP_TIMEVAL
public int tv_usec;
}

#if NET7_0_OR_GREATER
#if NET
[NativeMarshalling(typeof(PinningMarshaller))]
#endif
[StructLayout(LayoutKind.Sequential)]
Expand All @@ -185,7 +185,7 @@ internal sealed class BerVal
public int bv_len;
public IntPtr bv_val = IntPtr.Zero;

#if NET7_0_OR_GREATER
#if NET
[CustomMarshaller(typeof(BerVal), MarshalMode.ManagedToUnmanagedIn, typeof(PinningMarshaller))]
internal static unsafe class PinningMarshaller
{
Expand All @@ -207,7 +207,7 @@ internal sealed class LdapControl
public LdapControl() { }
}

#if NET7_0_OR_GREATER
#if NET
[NativeMarshalling(typeof(Marshaller))]
#endif
[StructLayout(LayoutKind.Sequential)]
Expand All @@ -217,7 +217,7 @@ internal struct LdapReferralCallback
public QUERYFORCONNECTIONInternal query;
public NOTIFYOFNEWCONNECTIONInternal notify;
public DEREFERENCECONNECTIONInternal dereference;
#if NET7_0_OR_GREATER
#if NET
public static readonly unsafe int Size = sizeof(Marshaller.MarshalValue.Native);

[CustomMarshaller(typeof(LdapReferralCallback), MarshalMode.ManagedToUnmanagedIn, typeof(MarshalValue))]
Expand Down
10 changes: 5 additions & 5 deletions src/libraries/Common/src/Interop/Interop.Odbc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Data.Odbc;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif
using System.Runtime.Versioning;
Expand Down Expand Up @@ -38,7 +38,7 @@ internal static partial ODBC32.SQLRETURN SQLAllocHandle(
/*SQLUSMALLINT*/ushort ColumnNumber,
/*SQLSMALLINT*/ODBC32.SQL_C TargetType,
/*SQLPOINTER*/
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef TargetValue,
Expand All @@ -64,13 +64,13 @@ internal static partial ODBC32.SQLRETURN SQLBindCol(
/*SQLULEN*/IntPtr cbColDef,
/*SQLSMALLINT*/IntPtr ibScale,
/*SQLPOINTER*/
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef rgbValue,
/*SQLLEN*/IntPtr BufferLength,
/*SQLLEN* */
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef StrLen_or_Ind);
Expand Down Expand Up @@ -326,7 +326,7 @@ internal static partial ODBC32.SQLRETURN SQLSetConnectAttrW(
/*SQLSMALLINT*/short ColumnNumber,
/*SQLSMALLINT*/ODBC32.SQL_DESC FieldIdentifier,
/*SQLPOINTER*/
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef CharacterAttribute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif
using Microsoft.Win32.SafeHandles;
Expand All @@ -13,7 +13,7 @@ internal static partial class Interop
{
internal static partial class CryptUI
{
#if NET7_0_OR_GREATER
#if NET
[NativeMarshalling(typeof(Marshaller))]
#else
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
Expand All @@ -39,7 +39,7 @@ internal struct CRYPTUI_VIEWCERTIFICATE_STRUCTW
internal IntPtr rgPropSheetPages;
internal uint nStartPage;

#if NET7_0_OR_GREATER
#if NET
[CustomMarshaller(typeof(CRYPTUI_VIEWCERTIFICATE_STRUCTW), MarshalMode.Default, typeof(Marshaller))]
public static class Marshaller
{
Expand Down Expand Up @@ -127,7 +127,7 @@ public CRYPTUI_VIEWCERTIFICATE_STRUCTW ToManaged()
#endif
}

#if NET7_0_OR_GREATER
#if NET
[NativeMarshalling(typeof(Marshaller))]
#else
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
Expand All @@ -151,7 +151,7 @@ internal struct CRYPTUI_SELECTCERTIFICATE_STRUCTW
internal IntPtr rgPropSheetPages;
internal IntPtr hSelectedCertStore;

#if NET7_0_OR_GREATER
#if NET
[CustomMarshaller(typeof(CRYPTUI_SELECTCERTIFICATE_STRUCTW), MarshalMode.Default, typeof(Marshaller))]
public static class Marshaller
{
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.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -12,7 +12,7 @@ internal static partial class Gdi32
{
[LibraryImport(Libraries.Gdi32, SetLastError = true)]
internal static partial int AbortDoc(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hDC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -13,7 +13,7 @@ internal static partial class Gdi32
{
[LibraryImport(Libraries.Gdi32, SetLastError = true)]
internal static partial IntPtr CreateCompatibleBitmap(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hDC, int width, int height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -13,7 +13,7 @@ internal static partial class Gdi32
{
[LibraryImport(Libraries.Gdi32, SetLastError = true)]
internal static partial IntPtr CreateDIBSection(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hdc, ref BITMAPINFO_FLAT bmi, int iUsage, ref IntPtr ppvBits, IntPtr hSection, int dwOffset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

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.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -12,7 +12,7 @@ internal static partial class Gdi32
{
[LibraryImport(Libraries.Gdi32, SetLastError = true)]
internal static partial int EndDoc(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hDC);
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.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -12,7 +12,7 @@ internal static partial class Gdi32
{
[LibraryImport(Libraries.Gdi32, SetLastError = true)]
internal static partial int EndPage(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hDC);
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.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -16,14 +16,14 @@ internal static partial class Gdi32

[LibraryImport(Libraries.Gdi32, SetLastError = true)]
internal static partial int ExtEscape(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hDC, int nEscape, int cbInput, ref int inData, int cbOutput, out int outData);

[LibraryImport(Libraries.Gdi32, SetLastError = true)]
internal static partial int ExtEscape(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hDC, int nEscape, int cbInput, byte[] inData, int cbOutput, out int outData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -13,11 +13,11 @@ internal static partial class Gdi32
{
[LibraryImport(Libraries.Gdi32)]
internal static partial int GetDIBits(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hdc,
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hbm, int arg1, int arg2, IntPtr arg3, ref BITMAPINFO_FLAT bmi, int arg5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -13,20 +13,20 @@ internal static partial class Gdi32
{
[LibraryImport(Libraries.Gdi32, EntryPoint = "GetObjectW", SetLastError = true)]
internal static partial int GetObject(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hObject, int nSize, ref BITMAP bm);

[LibraryImport(Libraries.Gdi32, EntryPoint = "GetObjectW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
internal static partial int GetObject(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hObject, int nSize, ref Interop.User32.LOGFONT lf);

internal static unsafe int GetObject(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hObject, ref Interop.User32.LOGFONT lp)
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.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -12,7 +12,7 @@ internal static partial class Gdi32
{
[LibraryImport(Libraries.Gdi32)]
internal static partial uint GetPaletteEntries(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hpal, int iStartIndex, int nEntries, byte[] lppe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Runtime.InteropServices;
#if NET7_0_OR_GREATER
#if NET
using System.Runtime.InteropServices.Marshalling;
#endif

Expand All @@ -13,7 +13,7 @@ internal static partial class Gdi32
{
[LibraryImport(Libraries.Gdi32, SetLastError = true)]
internal static partial int IntersectClipRect(
#if NET7_0_OR_GREATER
#if NET
[MarshalUsing(typeof(HandleRefMarshaller))]
#endif
HandleRef hDC, int x1, int y1, int x2, int y2);
Expand Down
Loading

0 comments on commit 2616119

Please sign in to comment.