Skip to content

Commit 41381de

Browse files
authored
refactor: Nullable and Modernization for Core projects (#2643)
* [Core.Mathematics] Modernize code * [Core.Mathematics] Add tests to Stride.Tests.Simple * [Core] Cleanup some code * [Core.CompilerServices] Cleanup some code * [Core.CompilerServices] Add tests to Stride.Tests.Simple * [Core.IO] Modernize code * [Core.MicroThreading] Modernize code * [Core.Serialization] Modernize code * [Core.AssemblyProcessor.Tests] Modernize code * [Core.CompilerServices.Tests] Modernize code * [Core.Mathematics.Tests] Modernize code * [Core.Tests] Modernize code * [Core.Translation] Modernize code * [Core.Reflection] Modernize code * Fixes build of Stride.VisualStudio.sln * [Core.Yaml.Tests] Modernize code * [Core.Design] Modernize code * [Core.Design.Tests] Modernize code * [Core.Mathematics] More annotations * Fix build of projects that import code from Core.Design Especially those targeting .NET Framework
1 parent 2080823 commit 41381de

File tree

463 files changed

+58483
-60159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

463 files changed

+58483
-60159
lines changed

build/Stride.Tests.Simple.slnf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"..\\sources\\assets\\Stride.Core.Assets.Quantum.Tests\\Stride.Core.Assets.Quantum.Tests.csproj",
66
"..\\sources\\assets\\Stride.Core.Assets.Tests\\Stride.Core.Assets.Tests.csproj",
77
"..\\sources\\buildengine\\Stride.Core.BuildEngine.Tests\\Stride.Core.BuildEngine.Tests.csproj",
8+
"..\\sources\\core\\Stride.Core.CompilerServices.Tests\\Stride.Core.CompilerServices.Tests.csproj",
89
"..\\sources\\core\\Stride.Core.Design.Tests\\Stride.Core.Design.Tests.csproj",
10+
"..\\sources\\core\\Stride.Core.Mathematics.Tests\\Stride.Core.Mathematics.Tests.csproj",
911
"..\\sources\\core\\Stride.Core.Tests\\Stride.Core.Tests.csproj",
1012
"..\\sources\\core\\Stride.Core.Yaml.Tests\\Stride.Core.Yaml.Tests.csproj",
1113
"..\\sources\\editor\\Stride.Core.Assets.Editor.Tests\\Stride.Core.Assets.Editor.Tests.csproj",

sources/assets/Stride.Core.Assets.CompilerApp/PackageBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ private BuildResultCode BuildSlave()
347347
}
348348

349349
// Create scheduler
350-
var scheduler = new Scheduler();
350+
using var scheduler = new Scheduler();
351351

352352
var status = ResultStatus.NotProcessed;
353353

sources/assets/Stride.Core.Assets.Tests/Stride.Core.Assets.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<PropertyGroup>
44
<TargetFramework>$(StrideEditorTargetFramework)</TargetFramework>
55
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<LangVersion>latest</LangVersion>
68
<StrideAssemblyProcessor>true</StrideAssemblyProcessor>
79
<StrideAssemblyProcessorOptions>--auto-module-initializer --serialization</StrideAssemblyProcessorOptions>
810
</PropertyGroup>

sources/buildengine/Stride.Core.BuildEngine.Common/FileVersionStorage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ protected override List<KeyValuePair<FileVersionKey, ObjectId>> ReadEntries(Syst
115115

116116
protected override void WriteEntry(Stream localStream, KeyValuePair<FileVersionKey, ObjectId> value)
117117
{
118+
ArgumentNullException.ThrowIfNull(localStream);
119+
118120
var key = value.Key;
119-
var line = string.Format("{0}\t{1}\t{2}\t{3}\n", key.Path, key.LastModifiedDate.Ticks, key.FileSize, value.Value);
121+
var line = $"{key.Path}\t{key.LastModifiedDate.Ticks}\t{key.FileSize}\t{value.Value}\n";
120122
var bytes = Encoding.UTF8.GetBytes(line);
121123
localStream.Write(bytes, 0, bytes.Length);
122124
}

sources/buildengine/Stride.Core.BuildEngine/BuildEngineCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static BuildResultCode BuildSlave(BuilderOptions options)
172172
RegisterRemoteLogger(processBuilderRemote);
173173

174174
// Create scheduler
175-
var scheduler = new Scheduler();
175+
using var scheduler = new Scheduler();
176176

177177
var status = ResultStatus.NotProcessed;
178178

sources/core/Stride.Core.AssemblyProcessor.Tests/Stride.Core.AssemblyProcessor.Tests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
55
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<LangVersion>latest</LangVersion>
9+
<Nullable>enable</Nullable>
710
</PropertyGroup>
811
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
912
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -31,4 +34,4 @@
3134
<ItemGroup>
3235
<None Include="app.config" />
3336
</ItemGroup>
34-
</Project>
37+
</Project>
Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,68 @@
11
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.IO;
74
using Mono.Cecil;
85
using Xunit;
96

10-
namespace Stride.Core.AssemblyProcessor.Tests
7+
namespace Stride.Core.AssemblyProcessor.Tests;
8+
9+
public class TestCecilExtensions
1110
{
12-
public class TestCecilExtensions
13-
{
14-
class Nested
15-
{
16-
}
11+
class Nested;
1712

18-
private readonly BaseAssemblyResolver assemblyResolver = new DefaultAssemblyResolver();
13+
private readonly BaseAssemblyResolver assemblyResolver = new DefaultAssemblyResolver();
1914

20-
public TestCecilExtensions()
21-
{
22-
// Add location of current assembly to MonoCecil search path.
23-
assemblyResolver.AddSearchDirectory(Path.GetDirectoryName(typeof(TestCecilExtensions).Assembly.Location));
24-
}
15+
public TestCecilExtensions()
16+
{
17+
// Add location of current assembly to MonoCecil search path.
18+
assemblyResolver.AddSearchDirectory(Path.GetDirectoryName(typeof(TestCecilExtensions).Assembly.Location));
19+
}
2520

26-
private string GenerateNameCecil(Type type)
27-
{
28-
var typeReference = type.GenerateTypeCecil(assemblyResolver);
21+
private string GenerateNameCecil(Type type)
22+
{
23+
var typeReference = type.GenerateTypeCecil(assemblyResolver);
2924

30-
return typeReference.ConvertAssemblyQualifiedName();
31-
}
25+
return typeReference.ConvertAssemblyQualifiedName();
26+
}
3227

33-
private static string GenerateNameDotNet(Type type)
34-
{
35-
return type.AssemblyQualifiedName;
36-
}
28+
private static string? GenerateNameDotNet(Type type)
29+
{
30+
return type.AssemblyQualifiedName;
31+
}
3732

38-
private void CheckGeneratedNames(Type type)
39-
{
40-
var nameCecil = GenerateNameCecil(type);
41-
var nameDotNet = GenerateNameDotNet(type);
42-
Assert.Equal(nameDotNet, nameCecil);
43-
}
33+
private void CheckGeneratedNames(Type type)
34+
{
35+
var nameCecil = GenerateNameCecil(type);
36+
var nameDotNet = GenerateNameDotNet(type);
37+
Assert.Equal(nameDotNet, nameCecil);
38+
}
4439

45-
[Fact]
46-
public void TestCecilDotNetAssemblyQualifiedNames()
47-
{
48-
// Primitive value type
49-
CheckGeneratedNames(typeof(bool));
40+
[Fact]
41+
public void TestCecilDotNetAssemblyQualifiedNames()
42+
{
43+
// Primitive value type
44+
CheckGeneratedNames(typeof(bool));
5045

51-
// Primitive class
52-
CheckGeneratedNames(typeof(string));
46+
// Primitive class
47+
CheckGeneratedNames(typeof(string));
5348

54-
// User class
55-
CheckGeneratedNames(typeof(TestCecilExtensions));
49+
// User class
50+
CheckGeneratedNames(typeof(TestCecilExtensions));
5651

57-
// Closed generics
58-
CheckGeneratedNames(typeof(Dictionary<string, object>));
52+
// Closed generics
53+
CheckGeneratedNames(typeof(Dictionary<string, object>));
5954

60-
// Open generics
61-
CheckGeneratedNames(typeof(Dictionary<,>));
55+
// Open generics
56+
CheckGeneratedNames(typeof(Dictionary<,>));
6257

63-
// Nested types
64-
CheckGeneratedNames(typeof(Nested));
58+
// Nested types
59+
CheckGeneratedNames(typeof(Nested));
6560

66-
// Arrays
67-
CheckGeneratedNames(typeof(string[]));
68-
CheckGeneratedNames(typeof(Dictionary<string, object>[]));
61+
// Arrays
62+
CheckGeneratedNames(typeof(string[]));
63+
CheckGeneratedNames(typeof(Dictionary<string, object>[]));
6964

70-
// Nullable
71-
CheckGeneratedNames(typeof(bool?));
72-
}
65+
// Nullable
66+
CheckGeneratedNames(typeof(bool?));
7367
}
7468
}

sources/core/Stride.Core.CompilerServices.Tests/AnalyzerTests/STRDIAG000_Test.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ namespace Stride.Core.CompilerServices.Tests.AnalyzerTests;
66
public class STRDIAG000_Test
77
{
88
[Fact]
9-
public void Error_On_Attribute_Contradiction_On_Property()
9+
public async Task Error_On_Attribute_Contradiction_On_Property()
1010
{
1111
string sourceCode = string.Format(ClassTemplates.BasicClassTemplate, "[DataMemberIgnore][DataMember]public int Value { get; set; }");
12-
TestHelper.ExpectDiagnosticsError(sourceCode, STRDIAG000AttributeContradiction.DiagnosticId);
12+
await TestHelper.ExpectDiagnosticsErrorAsync(sourceCode, STRDIAG000AttributeContradiction.DiagnosticId);
1313
}
1414

1515
[Fact]
16-
public void Error_On_Attribute_Contradiction_On_Field()
16+
public async Task Error_On_Attribute_Contradiction_On_Field()
1717
{
1818
string sourceCode = string.Format(ClassTemplates.BasicClassTemplate, "[DataMemberIgnore][DataMember]public int Value;");
19-
TestHelper.ExpectDiagnosticsError(sourceCode, STRDIAG000AttributeContradiction.DiagnosticId);
19+
await TestHelper.ExpectDiagnosticsErrorAsync(sourceCode, STRDIAG000AttributeContradiction.DiagnosticId);
2020
}
2121

2222
[Fact]
23-
public void NoErrorOn_Attribute_Contradiction_With_Updatable()
23+
public async Task NoErrorOn_Attribute_Contradiction_With_Updatable()
2424
{
25-
string sourceCode = @"
25+
const string sourceCode = @"
2626
using System;
2727
using Stride.Core;
2828
using Stride.Updater;
@@ -46,6 +46,6 @@ public class TripleAnnotation
4646
}
4747
}
4848
";
49-
TestHelper.ExpectNoDiagnosticsErrors(sourceCode);
49+
await TestHelper.ExpectNoDiagnosticsErrorsAsync(sourceCode);
5050
}
5151
}
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
61
using Stride.Core.CompilerServices.Analyzers;
72
using Xunit;
83

94
namespace Stride.Core.CompilerServices.Tests.AnalyzerTests;
105
public class STRDIAG001_Test
116
{
127
[Fact]
13-
public void Error_On_Private_Inner_Class_with_DataContract()
8+
public async Task Error_On_Private_Inner_Class_with_DataContract()
149
{
1510
string sourceCode = string.Format(ClassTemplates.BasicClassTemplate, "[DataContract] private class InnerClass { }");
16-
TestHelper.ExpectDiagnosticsError(sourceCode, STRDIAG001InvalidDataContract.DiagnosticId);
11+
await TestHelper.ExpectDiagnosticsErrorAsync(sourceCode, STRDIAG001InvalidDataContract.DiagnosticId);
1712
}
1813
[Fact]
19-
public void No_Error_On_Private_Inner_Class_without_DataContract()
14+
public async Task No_Error_On_Private_Inner_Class_without_DataContract()
2015
{
2116
string sourceCode = string.Format(ClassTemplates.BasicClassTemplate, "private class InnerClass { }");
22-
TestHelper.ExpectNoDiagnosticsErrors(sourceCode);
17+
await TestHelper.ExpectNoDiagnosticsErrorsAsync(sourceCode);
2318
}
2419
[Fact]
25-
public void Error_On_file_scope_Class_with_DataContract()
20+
public async Task Error_On_file_scope_Class_with_DataContract()
2621
{
2722
string sourceCode = "using Stride.Core; [DataContract] file class FileScopeClass { }";
28-
TestHelper.ExpectDiagnosticsError(sourceCode, STRDIAG001InvalidDataContract.DiagnosticId);
23+
await TestHelper.ExpectDiagnosticsErrorAsync(sourceCode, STRDIAG001InvalidDataContract.DiagnosticId);
2924
}
3025
[Fact]
31-
public void No_Error_On_file_scope_Class_without_DataContract()
26+
public async Task No_Error_On_file_scope_Class_without_DataContract()
3227
{
3328
string sourceCode = "using Stride.Core; file class FileScopeClass { }";
34-
TestHelper.ExpectNoDiagnosticsErrors(sourceCode);
29+
await TestHelper.ExpectNoDiagnosticsErrorsAsync(sourceCode);
3530
}
3631
}

sources/core/Stride.Core.CompilerServices.Tests/AnalyzerTests/STRDIAG002_Test.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace Stride.Core.CompilerServices.Tests.AnalyzerTests;
66
public class STRDIAG002_Test
77
{
88
[Fact]
9-
public void Error_On_Attribute_Contradiction_On_Property()
9+
public async Task Error_On_Attribute_Contradiction_On_Property()
1010
{
1111
string sourceCode = string.Format(ClassTemplates.BasicClassTemplate, "[DataMember(DataMemberMode.Content)]public int Value { get; set; }");
12-
TestHelper.ExpectDiagnosticsError(sourceCode, STRDIAG002InvalidContentMode.DiagnosticId);
12+
await TestHelper.ExpectDiagnosticsErrorAsync(sourceCode, STRDIAG002InvalidContentMode.DiagnosticId);
1313
}
1414
}

0 commit comments

Comments
 (0)