Skip to content

Commit d8735b6

Browse files
chore: Update to C# 12.0 (#257)
1 parent c3a9cf3 commit d8735b6

17 files changed

+65
-76
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
33
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
4-
<LangVersion>11.0</LangVersion>
4+
<LangVersion>12.0</LangVersion>
55
</PropertyGroup>
66
</Project>

IntelliTect.Analyzer/IntelliTect.Analyzer.Integration.Tests/AnalyzerTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ await ProcessProject(new FileInfo(Path.Combine("..", "..", "..", "..", "IntelliT
2929

3030
public static async Task ProcessProject(FileInfo projectFile)
3131
{
32-
if (projectFile is null)
33-
{
34-
throw new ArgumentNullException(nameof(projectFile));
35-
}
32+
ArgumentNullException.ThrowIfNull(projectFile);
3633

3734
using var workspace = MSBuildWorkspace.Create();
3835
Project project = await workspace.OpenProjectAsync(projectFile.FullName).ConfigureAwait(false);

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AsyncVoidTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public async void Sample() { }
5656
Message = "Async methods should not return void",
5757
Severity = DiagnosticSeverity.Warning,
5858
Locations =
59-
new[] {
59+
[
6060
new DiagnosticResultLocation("Test0.cs", 13, 31)
61-
}
61+
]
6262
};
6363

6464
VerifyCSharpDiagnostic(test, expected);

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ private static DiagnosticResult GetExpectedDiagnosticResult(int line, int col)
398398
Message = "Attributes should be on separate lines",
399399
Severity = DiagnosticSeverity.Warning,
400400
Locations =
401-
new[] {
401+
[
402402
new DiagnosticResultLocation("Test0.cs", line, col)
403-
}
403+
]
404404
};
405405
}
406406

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/DateTimeConversionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ static void Main(string[] args)
3232
Severity = DiagnosticSeverity.Warning,
3333
Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior",
3434
Locations =
35-
new[] {
35+
[
3636
new DiagnosticResultLocation("Test0.cs", 10, 38)
37-
}
37+
]
3838
});
3939

4040
}
@@ -73,9 +73,9 @@ static void Main(string[] args)
7373
Severity = DiagnosticSeverity.Warning,
7474
Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior",
7575
Locations =
76-
new[] {
76+
[
7777
new DiagnosticResultLocation("Test0.cs", 17, 17)
78-
}
78+
]
7979
});
8080

8181
}

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/FavorEnumeratorDirectoryCallsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ static void Main(string[] args)
3737
Severity = DiagnosticSeverity.Info,
3838
Message = "Favor using the method `EnumerateFiles` over the `GetFiles` method",
3939
Locations =
40-
new[] {
40+
[
4141
new DiagnosticResultLocation("Test0.cs", 11, 30)
42-
}
42+
]
4343
});
4444
}
4545

@@ -105,9 +105,9 @@ static void Main(string[] args)
105105
Severity = DiagnosticSeverity.Info,
106106
Message = "Favor using the method `EnumerateDirectories` over the `GetDirectories` method",
107107
Locations =
108-
new[] {
108+
[
109109
new DiagnosticResultLocation("Test0.cs", 11, 30)
110-
}
110+
]
111111
});
112112
}
113113

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/CodeFixVerifier.Helper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ private static async Task<Document> ApplyFix(Document document, CodeAction codeA
3939
/// <returns>A list of Diagnostics that only surfaced in the code after the CodeFix was applied</returns>
4040
private static IEnumerable<Diagnostic> GetNewDiagnostics(IEnumerable<Diagnostic> diagnostics, IEnumerable<Diagnostic> newDiagnostics)
4141
{
42-
Diagnostic[] oldArray = diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
43-
Diagnostic[] newArray = newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
42+
Diagnostic[] oldArray = [.. diagnostics.OrderBy(d => d.Location.SourceSpan.Start)];
43+
Diagnostic[] newArray = [.. newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start)];
4444

4545
int oldIndex = 0;
4646
int newIndex = 0;

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public DiagnosticResultLocation[] Locations
4343
{
4444
get
4545
{
46-
_Locations ??= Array.Empty<DiagnosticResultLocation>();
46+
_Locations ??= [];
4747
return _Locations;
4848
}
4949

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ private static Diagnostic[] GetSortedDiagnostics(string[] sources, string langua
4848
/// <returns>An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location</returns>
4949
protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer analyzer, Document[] documents)
5050
{
51-
if (documents is null)
52-
{
53-
throw new ArgumentNullException(nameof(documents));
54-
}
51+
ArgumentNullException.ThrowIfNull(documents);
5552

5653
var projects = new HashSet<Project>();
5754
foreach (Document document in documents)
@@ -97,7 +94,7 @@ protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyz
9794
/// <returns>An IEnumerable containing the Diagnostics in order of Location</returns>
9895
private static Diagnostic[] SortDiagnostics(IEnumerable<Diagnostic> diagnostics)
9996
{
100-
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
97+
return [.. diagnostics.OrderBy(d => d.Location.SourceSpan.Start)];
10198
}
10299

103100
#endregion
@@ -135,7 +132,7 @@ private static Document[] GetDocuments(string[] sources, string language)
135132
/// <returns>A Document created from the source string</returns>
136133
protected static Document CreateDocument(string source, string language = LanguageNames.CSharp)
137134
{
138-
return CreateProject(new[] { source }, language).Documents.First();
135+
return CreateProject([source], language).Documents.First();
139136
}
140137

141138
/// <summary>

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingFieldPascalUnderscoreTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class TypeName
7979
Message = "Field 'MyField' should be named _PascalCase",
8080
Severity = DiagnosticSeverity.Warning,
8181
Locations =
82-
new[] {
82+
[
8383
new DiagnosticResultLocation("Test0.cs", 13, 27)
84-
}
84+
]
8585
};
8686

8787
VerifyCSharpDiagnostic(test, expected);
@@ -111,9 +111,9 @@ class TypeName
111111
Message = "Field '_myField' should be named _PascalCase",
112112
Severity = DiagnosticSeverity.Warning,
113113
Locations =
114-
new[] {
114+
[
115115
new DiagnosticResultLocation("Test0.cs", 13, 27)
116-
}
116+
]
117117
};
118118

119119
VerifyCSharpDiagnostic(test, expected);
@@ -143,9 +143,9 @@ class TypeName
143143
Message = "Field '__myField' should be named _PascalCase",
144144
Severity = DiagnosticSeverity.Warning,
145145
Locations =
146-
new[] {
146+
[
147147
new DiagnosticResultLocation("Test0.cs", 13, 27)
148-
}
148+
]
149149
};
150150

151151
VerifyCSharpDiagnostic(test, expected);
@@ -443,9 +443,9 @@ class TypeName
443443
Message = "Field '_My_Field' should be named _PascalCase",
444444
Severity = DiagnosticSeverity.Warning,
445445
Locations =
446-
new[] {
446+
[
447447
new DiagnosticResultLocation("Test0.cs", 13, 27)
448-
}
448+
]
449449
};
450450

451451
VerifyCSharpDiagnostic(test, expected);

0 commit comments

Comments
 (0)