Skip to content

Commit cfaa576

Browse files
authored
Task 38349: Set LangVersion to 13 for all targets (#3588)
- Explicitly setting C# language version to 13 for all targets. - Adding IDisposable to ref structs where appropriate.
1 parent 1297673 commit cfaa576

File tree

7 files changed

+16
-19
lines changed

7 files changed

+16
-19
lines changed

src/Directory.Build.props

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,20 @@
113113
</PropertyGroup>
114114

115115
<!--
116-
For non-.NET, we explicitly set the C# language version to 13. This matches
117-
the language version used by the .NET 9 SDK, and provides helpful modern
118-
language features. While this isn't strictly supported by .NET in general,
119-
it works well in practice. There are very few C# language features that
120-
depend on SDK APIs, and we avoid them.
116+
We want to use the latest C# language regardless of target framework,
117+
so we explicitly set LangVersion for all targets.
121118
122-
For .NET, we omit this property entirely, which results in the SDK choosing
123-
the C# language version that matches the .NET version.
119+
We will roll this version forward as new C# language versions are released
120+
and associated with the newest .NET SDK we support.
124121
125122
Details here:
126123
127124
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-versioning
128125
129126
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version
130127
-->
131-
<PropertyGroup
132-
Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))' != '.NETCoreApp'">
133-
<LangVersion>13.0</LangVersion>
128+
<PropertyGroup>
129+
<!-- The newest .NET SDK we support is .NET 9.0, which uses C# 13 -->
130+
<LangVersion>13</LangVersion>
134131
</PropertyGroup>
135132
</Project>

src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,23 +1497,23 @@ internal static Exception NumericToDecimalOverflow()
14971497
}
14981498

14991499
//
1500-
// : IDbCommand
1500+
// IDbCommand
15011501
//
15021502
internal static Exception InvalidCommandTimeout(int value, string name)
15031503
{
15041504
return Argument(StringsHelper.GetString(Strings.ADP_InvalidCommandTimeout, value.ToString(CultureInfo.InvariantCulture)), name);
15051505
}
15061506

15071507
//
1508-
// : DbDataAdapter
1508+
// DbDataAdapter
15091509
//
15101510
internal static InvalidOperationException ComputerNameEx(int lastError)
15111511
{
15121512
return InvalidOperation(StringsHelper.GetString(Strings.ADP_ComputerNameEx, lastError));
15131513
}
15141514

15151515
//
1516-
// : SNI
1516+
// SNI
15171517
//
15181518
internal static PlatformNotSupportedException SNIPlatformNotSupported(string platform) => new(StringsHelper.GetString(Strings.SNI_PlatformNotSupportedNetFx, platform));
15191519

@@ -1635,7 +1635,7 @@ internal static ArgumentOutOfRangeException InvalidParameterDirection(ParameterD
16351635
}
16361636

16371637
//
1638-
// : IDbCommand
1638+
// IDbCommand
16391639
//
16401640
internal static Exception InvalidCommandTimeout(int value, [CallerMemberName] string property = "")
16411641
=> Argument(StringsHelper.GetString(Strings.ADP_InvalidCommandTimeout, value.ToString(CultureInfo.InvariantCulture)), property);

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Diagnostics/DiagnosticScope.netcore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Microsoft.Data.SqlClient.Diagnostics
1111
{
12-
internal ref struct DiagnosticScope //: IDisposable
12+
internal ref struct DiagnosticScope : IDisposable
1313
{
1414
private const int CommandOperation = 1;
1515
private const int ConnectionOpenOperation = 2;

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Diagnostics/DiagnosticTransactionScope.netcore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Microsoft.Data.SqlClient.Diagnostics
1212
{
13-
internal ref struct DiagnosticTransactionScope //: IDisposable
13+
internal ref struct DiagnosticTransactionScope : IDisposable
1414
{
1515
public const int TransactionCommit = 1;
1616
public const int TransactionRollback = 2;

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEventSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ public static TrySNIEventScope Create(string className, [System.Runtime.Compiler
11391139
=> new TrySNIEventScope(SqlClientEventSource.Log.TrySNIScopeEnterEvent(className, memberName));
11401140
}
11411141

1142-
internal readonly ref struct TryEventScope //: IDisposable
1142+
internal readonly ref struct TryEventScope : IDisposable
11431143
{
11441144
private readonly long _scopeId;
11451145

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlStatistics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ void ICollection.CopyTo(Array array, int arrayIndex)
341341
// This is a ref struct to prevent it being included in async closures accidentally.
342342
// Async functions should manage the timer directly using the Start and Stop method
343343
// in their invoke and completion functions
344-
internal readonly ref struct ValueSqlStatisticsScope // : IDisposable // ref structs cannot implement interfaces but the compiler will use pattern matching to allow use of using on them
344+
internal readonly ref struct ValueSqlStatisticsScope : IDisposable
345345
{
346346
private readonly SqlStatistics _statistics;
347347

src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ protected virtual void OnMatchingEventWritten(EventWrittenEventArgs eventData)
12161216
}
12171217
}
12181218

1219-
public readonly ref struct XEventScope // : IDisposable
1219+
public readonly ref struct XEventScope : IDisposable
12201220
{
12211221
private const int MaxXEventsLatencyS = 5;
12221222

0 commit comments

Comments
 (0)