Skip to content

Commit

Permalink
Streamline conditional compilation symbols (#2486)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ authored May 14, 2024
1 parent 9a71c94 commit cc6ea21
Show file tree
Hide file tree
Showing 48 changed files with 75 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public static partial class SqlClientMetaDataCollectionNames
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml' path='docs/members[@name="SqlClientMetaDataCollectionNames"]/StructuredTypeMembers/*' />
public static readonly string StructuredTypeMembers;
}
#if NETCOREAPP
#if NET6_0_OR_GREATER
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionAttestationProtocol.xml' path='docs/members[@name="SqlConnectionAttestationProtocol"]/SqlConnectionAttestationProtocol/*' />
public enum SqlConnectionAttestationProtocol
{
Expand Down Expand Up @@ -1017,7 +1017,7 @@ public SqlConnectionStringBuilder(string connectionString) { }
[System.ComponentModel.DisplayNameAttribute("Data Source")]
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
public string DataSource { get { throw null; } set { } }
#if NETCOREAPP
#if NET6_0_OR_GREATER
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionStringBuilder.xml' path='docs/members[@name="SqlConnectionStringBuilder"]/AttestationProtocol/*' />
[System.ComponentModel.DisplayNameAttribute("Attestation Protocol")]
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
Expand Down Expand Up @@ -1444,7 +1444,7 @@ internal SqlException() { }
public byte State { get { throw null; } }

/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlException.xml' path='docs/members[@name="SqlException"]/GetObjectData/*'/>
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)]
#endif
#if NET8_0_OR_GREATER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static partial class Libraries
internal const string Crypt32 = "crypt32.dll";
internal const string Kernel32 = "kernel32.dll";
internal const string NtDll = "ntdll.dll";
#if !NET7_0_OR_GREATER
#if !NET8_0_OR_GREATER
internal const string SspiCli = "sspicli.dll";
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using System.Diagnostics.Tracing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if net462
#if NETFRAMEWORK
using System.Security;
#endif

Expand Down Expand Up @@ -45,7 +45,7 @@ namespace System.Net
// method that takes an object and optionally provides a string representation of it, in case a particular library wants to customize further.

/// <summary>Provides logging facilities for System.Net libraries.</summary>
#if net462
#if NETFRAMEWORK
[SecuritySafeCritical]
#endif
internal sealed partial class NetEventSource : EventSource
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.
// See the LICENSE file in the project root for more information.

#if NETCOREAPP
#if NET6_0_OR_GREATER

using System.Diagnostics;
using Microsoft.Data.Common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectio
throw;
}

#if NETCOREAPP
#if NET6_0_OR_GREATER
if (!IsBlockingPeriodEnabled())
{
throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ internal static bool ValidateSslServerCertificate(string targetServerName, X509C

if (policyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch))
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
X509Certificate2 cert2 = cert as X509Certificate2;
if (!cert2.MatchesHostname(targetServerName))
{
Expand Down Expand Up @@ -297,7 +297,7 @@ internal static bool ValidateSslServerCertificate(X509Certificate clientCert, X5

if (policyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch))
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
X509Certificate2 s_cert = serverCert as X509Certificate2;
X509Certificate2 c_cert = clientCert as X509Certificate2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class SNIProxy
private static readonly SNIProxy s_singleton = new SNIProxy();

internal static SNIProxy Instance => s_singleton;
#if !NET7_0_OR_GREATER
#if !NET8_0_OR_GREATER
/// <summary>
/// Generate SSPI context
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ public override void KillConnection()

internal static void SetKeepAliveValues(ref Socket socket)
{
#if NETCOREAPP
#if NET6_0_OR_GREATER
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, 1);
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, 30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3994,7 +3994,7 @@ private SqlDataReader GetParameterEncryptionDataReader(out Task returnTask, Task
SqlCommand command = (SqlCommand)state;
bool processFinallyBlockAsync = true;
bool decrementAsyncCountInFinallyBlockAsync = true;
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
Expand Down Expand Up @@ -4068,7 +4068,7 @@ private SqlDataReader GetParameterEncryptionDataReaderAsync(out Task returnTask,
bool processFinallyBlockAsync = true;
bool decrementAsyncCountInFinallyBlockAsync = true;
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
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.
// See the LICENSE file in the project root for more information.

#if NETCOREAPP
#if NET6_0_OR_GREATER

using System;
using System.Reflection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ override public string GetName(int i)
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetProviderSpecificFieldType/*' />
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
override public Type GetProviderSpecificFieldType(int i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void Initialize()
SqlInternalConnection connection = _connection;
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Initialize | RES | CPOOL | Object Id {0}, Client Connection Id {1}, delegating transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
Expand Down Expand Up @@ -146,7 +146,7 @@ public byte[] Promote()
{
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Promote | RES | CPOOL | Object Id {0}, Client Connection Id {1}, promoting transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
Expand Down Expand Up @@ -256,7 +256,7 @@ public void Rollback(SinglePhaseEnlistment enlistment)
{
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Rollback | RES | CPOOL | Object Id {0}, Client Connection Id {1}, rolling back transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
Expand Down Expand Up @@ -343,7 +343,7 @@ public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
{
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.SinglePhaseCommit | RES | CPOOL | Object Id {0}, Client Connection Id {1}, committing transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,7 @@ internal bool TryGetFedAuthTokenLocked(SqlFedAuthInfo fedAuthInfo, DbConnectionP
bool authenticationContextLocked = false;

// Prepare CER to ensure the lock on authentication context is released.
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ internal void WriteInt(int v, TdsParserStateObject stateObj)

internal static void WriteInt(Span<byte> buffer, int value)
{
#if NETCOREAPP
#if NET6_0_OR_GREATER
BinaryPrimitives.TryWriteInt32LittleEndian(buffer, value);
#else
buffer[0] = (byte)(value & 0xff);
Expand Down Expand Up @@ -6144,7 +6144,7 @@ internal bool TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, int length, T
}
else
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
value.SqlBinary = SqlBinary.WrapBytes(b);
#else
value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor(b, true); // doesn't copy the byte array
Expand Down Expand Up @@ -6441,7 +6441,7 @@ internal bool TryReadSqlValueInternal(SqlBuffer value, byte tdsType, int length,
{
return false;
}
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
value.SqlBinary = SqlBinary.WrapBytes(b);
#else
value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor(b, true);
Expand Down Expand Up @@ -7313,7 +7313,7 @@ internal byte[] SerializeSqlDecimal(SqlDecimal d, TdsParserStateObject stateObj)


Span<uint> data = stackalloc uint[4];
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
d.WriteTdsValue(data);
#else
SqlTypeWorkarounds.SqlDecimalExtractData(d, out data[0], out data[1], out data[2], out data[3]);
Expand Down Expand Up @@ -7342,7 +7342,7 @@ internal void WriteSqlDecimal(SqlDecimal d, TdsParserStateObject stateObj)
stateObj.WriteByte(0);

Span<uint> data = stackalloc uint[4];
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
d.WriteTdsValue(data);
#else
SqlTypeWorkarounds.SqlDecimalExtractData(d, out data[0], out data[1], out data[2], out data[3]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private SNIHandle GetSessionSNIHandleHandleOrThrow()
private void ThrowClosedConnection() => throw ADP.ClosedConnectionError();

internal override SSPIContextProvider CreateSSPIContextProvider()
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
=> new NegotiateSSPIContextProvider();
#else
=> new ManagedSSPIContextProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ internal override uint WaitForSSLHandShakeToComplete(out int protocolVersion)
{
protocolVersion = (int)SslProtocols.Tls12;
}
#if NETCOREAPP
#if NET6_0_OR_GREATER
else if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_SERVER))
{
/* The SslProtocols.Tls13 is supported by netcoreapp3.1 and later */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public override void Flush()
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlFileStream.xml' path='docs/members[@name="SqlFileStream"]/BeginRead/*' />
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
[HostProtection(ExternalThreading = true)]
#endif
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Expand All @@ -318,7 +318,7 @@ public override int EndRead(IAsyncResult asyncResult)
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlFileStream.xml' path='docs/members[@name="SqlFileStream"]/BeginWrite/*' />
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
[HostProtection(ExternalThreading = true)]
#endif
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static partial class ADP
[ResourceConsumption(ResourceScope.Machine)]
internal static object LocalMachineRegistryValue(string subkey, string queryvalue)
{ // MDAC 77697
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\" + subkey)).Assert(); // MDAC 62028
#endif
try
Expand All @@ -43,7 +43,7 @@ internal static object LocalMachineRegistryValue(string subkey, string queryvalu
ADP.TraceExceptionWithoutRethrow(e);
return null;
}
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
finally
{
RegistryPermission.RevertAssert();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ private static long TimerToSeconds(long timerValue)
/// Note: In Longhorn you'll be able to rename a machine without
/// rebooting. Therefore, don't cache this machine name.
/// </summary>
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
[EnvironmentPermission(SecurityAction.Assert, Read = "COMPUTERNAME")]
#endif
internal static string MachineName() => Environment.MachineName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal bool LockToUpdate()
/// <summary>
/// Release the lock which was obtained through LockToUpdate.
/// </summary>
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#endif
internal void ReleaseLockToUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static class SqlDataSourceEnumeratorNativeHelper
/// <returns></returns>
internal static DataTable GetDataSources()
{
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
(new NamedPermissionSet("FullTrust")).Demand(); // SQLBUDT 244304
#endif
char[] buffer = null;
Expand All @@ -37,13 +37,13 @@ internal static DataTable GetDataSources()
bool more = true;
bool failure = false;
IntPtr handle = ADP.s_ptrZero;
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
{
long s_timeoutTime = TdsParserStaticMethods.GetTimeoutSeconds(ADP.DefaultCommandTimeout);
#if !NET6_0_OR_GREATER
#if NETFRAMEWORK
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenti
*/
string redirectUri = s_nativeClientRedirectUri;

#if NETCOREAPP
#if NET6_0_OR_GREATER
if (parameters.AuthenticationMethod != SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow)
{
redirectUri = "http://localhost";
Expand Down Expand Up @@ -361,7 +361,7 @@ private static async Task<AuthenticationResult> AcquireTokenInteractiveDeviceFlo
if (authenticationMethod == SqlAuthenticationMethod.ActiveDirectoryInteractive)
{
CancellationTokenSource ctsInteractive = new CancellationTokenSource();
#if NETCOREAPP
#if NET6_0_OR_GREATER
/*
* On .NET Core, MSAL will start the system browser as a separate process. MSAL does not have control over this browser,
* but once the user finishes authentication, the web page is redirected in such a way that MSAL can intercept the Uri.
Expand Down Expand Up @@ -492,8 +492,6 @@ private IPublicClientApplication CreateClientAppInstance(PublicClientAppKey publ
.WithParentActivityOrWindow(_iWin32WindowFunc)
.Build();
}
#endif
#if !NETCOREAPP
else
#endif
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private enum Tristate : byte
private static Tristate s_makeReadAsyncBlocking;
private static Tristate s_useMinimumLoginTimeout;

#if !NETFRAMEWORK
#if NET6_0_OR_GREATER
static LocalAppContextSwitches()
{
IAppContextSwitchOverridesSection appContextSwitch = AppConfigManager.FetchConfigurationSection<AppContextSwitchOverridesSection>(AppContextSwitchOverridesSection.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SqlConfigurableRetryLogicLoader(ISqlConfigurableRetryConnectionSection co
string cnnSectionName = SqlConfigurableRetryConnectionSection.Name,
string cmdSectionName = SqlConfigurableRetryCommandSection.Name)
{
#if !NETFRAMEWORK
#if NET6_0_OR_GREATER
// Just only one subscription to this event is required.
// This class isn't supposed to be called more than one time;
// SqlConfigurableRetryLogicManager manages a single instance of this class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETFRAMEWORK && !NET7_0_OR_GREATER
#if NET6_0

using System;
using Microsoft.Data.SqlClient.SNI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER

using System;
using System.Text;
Expand Down
Loading

0 comments on commit cc6ea21

Please sign in to comment.