Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public int Run(string[] args)
{ "log", "Enable file logging", v => options.EnableFileLogging = v != null },
{ "disable-auto-compile", "Disable auto-compile of projects", v => options.DisableAutoCompileProjects = v != null},
{ "project-configuration=", "Project configuration", v => options.ProjectConfiguration = v },
{ "platform=", "Platform name", v => options.Platform = (PlatformType)Enum.Parse(typeof(PlatformType), v) },
{ "platform=", "Platform name", v => options.Platform = Enum.Parse<PlatformType>(v) },
{ "solution-file=", "Solution File Name", v => options.SolutionFile = v },
{ "package-id=", "Package Id from the solution file", v => options.PackageId = Guid.Parse(v) },
{ "package-file=", "Input Package File Name", v => options.PackageFile = v },
Expand Down
2 changes: 1 addition & 1 deletion sources/assets/Stride.Core.Assets/DefaultAssetFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DefaultAssetFactory<T> : AssetFactory<T> where T : Asset
{
public static T Create()
{
return (T)Activator.CreateInstance(typeof(T))!;
return Activator.CreateInstance<T>()!;
}

/// <inheritdoc/>
Expand Down
5 changes: 5 additions & 0 deletions sources/assets/Stride.Core.Assets/PackageSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,11 @@ public override bool Equals(object? obj)
return Equals(obj as PendingPackageUpgrade);
}

public override int GetHashCode()
{
return HashCode.Combine(PackageUpgrader, Dependency, DependencyPackage, DependencyVersionBeforeUpgrade);
}

public PendingPackageUpgrade Clone()
{
return new PendingPackageUpgrade(PackageUpgrader, Dependency.Clone(), DependencyPackage);
Expand Down
2 changes: 1 addition & 1 deletion sources/assets/Stride.Core.Assets/VSProjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static Guid GetProjectGuid(MicrosoftProject project)
{
return null;
}
return (T)Enum.Parse(typeof(T), value);
return Enum.Parse<T>(value);
}

public static string GetOrCompileProjectAssembly(string fullProjectLocation, ILogger logger, string targets, bool autoCompileProject, string configuration, string platform = "AnyCPU", Dictionary<string, string>? extraProperties = null, bool onlyErrors = false, BuildRequestDataFlags flags = BuildRequestDataFlags.None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class StepCounter

public StepCounter()
{
stepResults = new int[Enum.GetValues(typeof(ResultStatus)).Length];
stepResults = new int[Enum.GetValues<ResultStatus>().Length];
}

public void AddStepResult(ResultStatus result)
Expand All @@ -35,7 +35,7 @@ public void Clear()
lock (stepResults)
{
Total = 0;
foreach (var value in Enum.GetValues(typeof(ResultStatus)))
foreach (var value in Enum.GetValues<ResultStatus>())
stepResults[(int)value] = 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private void Generate(SourceProductionContext context, ImmutableArray<OrderedMod
}
}
var outputClass = @$"
// <auto-generated/>
namespace Stride.Core.CompilerServices.AutoGenerated.ModuleInitializer
{{
file static class ModuleInitializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Remove_ExistingKey_ShouldRemoveAndReturnTrue()
var result = dictionary.Remove("key1");

Assert.True(result);
Assert.Equal(1, dictionary.Count);
Assert.Single(dictionary);
Assert.False(dictionary.ContainsKey("key1"));
}

Expand All @@ -115,7 +115,7 @@ public void Remove_NonExistingKey_ShouldReturnFalse()
var result = dictionary.Remove("key2");

Assert.False(result);
Assert.Equal(1, dictionary.Count);
Assert.Single(dictionary);
}

[Fact]
Expand Down Expand Up @@ -202,7 +202,7 @@ public void Clear_WithItems_ShouldRemoveAllItems()

dictionary.Clear();

Assert.Equal(0, dictionary.Count);
Assert.Empty(dictionary);
}

[Fact]
Expand Down Expand Up @@ -249,7 +249,7 @@ public void GetEnumerator_ShouldEnumerateAllItems()
foreach (var kvp in dictionary)
{
count++;
Assert.True(kvp.Key.StartsWith("key"));
Assert.StartsWith("key", kvp.Key);
}

Assert.Equal(3, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void TestBoundingSphereMerge()
BoundingSphere.Merge(ref sphere1, ref sphere2, out var merged);

// Merged sphere should contain both spheres
Assert.True(merged.Contains(ref sphere1) != ContainmentType.Disjoint);
Assert.True(merged.Contains(ref sphere2) != ContainmentType.Disjoint);
Assert.NotEqual(ContainmentType.Disjoint, merged.Contains(ref sphere1));
Assert.NotEqual(ContainmentType.Disjoint, merged.Contains(ref sphere2));

// Test non-ref version
var merged2 = BoundingSphere.Merge(sphere1, sphere2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ public void TestSphericalHarmonicsEvaluate_Order2()
var result = sh.Evaluate(direction);

// Verify result is valid (SH can produce negative or positive values)
Assert.True(!float.IsNaN(result.R));
Assert.True(!float.IsNaN(result.G));
Assert.True(!float.IsNaN(result.B));
Assert.False(float.IsNaN(result.R));
Assert.False(float.IsNaN(result.G));
Assert.False(float.IsNaN(result.B));
}

[Fact]
Expand Down
7 changes: 1 addition & 6 deletions sources/core/Stride.Core.Mathematics/Rectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ public struct Rectangle : IEquatable<Rectangle>, ISpanFormattable
/// <summary>
/// An empty rectangle.
/// </summary>
public static readonly Rectangle Empty;

static Rectangle()
{
Empty = new Rectangle();
}
public static readonly Rectangle Empty = new();

/// <summary>
/// Initializes a new instance of the <see cref="Rectangle"/> struct.
Expand Down
7 changes: 1 addition & 6 deletions sources/core/Stride.Core.Mathematics/RectangleF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ public struct RectangleF : IEquatable<RectangleF>, ISpanFormattable
/// <summary>
/// An empty rectangle
/// </summary>
public static readonly RectangleF Empty;

static RectangleF()
{
Empty = new RectangleF();
}
public static readonly RectangleF Empty = new();

/// <summary>
/// Initializes a new instance of the <see cref="RectangleF"/> struct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override Stream OpenStream(string url, VirtualFileMode mode, VirtualFileA
if (streamFlags == StreamFlags.Seekable && !result.CanSeek)
{
var buffer = new byte[result.Length - result.Position];
result.Read(buffer, 0, buffer.Length);
result.ReadExactly(buffer, 0, buffer.Length);
return new DatabaseReadFileStream(objectId, new MemoryStream(buffer), 0);
}

Expand Down
2 changes: 1 addition & 1 deletion sources/core/Stride.Core.Serialization/IO/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private void RefreshData(long fileSize)
return;

var bufferToRead = new byte[length];
stream.Read(bufferToRead, 0, length);
stream.ReadExactly(bufferToRead, 0, length);
var memoryStream = new MemoryStream(bufferToRead);

try
Expand Down
2 changes: 1 addition & 1 deletion sources/core/Stride.Core.Serialization/Storage/Blob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal unsafe Blob(ObjectDatabase objectDatabase, ObjectId objectId, Stream st
{
Size = (int)stream.Length;
Content = Marshal.AllocHGlobal(Size);
stream.Read(new Span<byte>((void*)Content, Size));
stream.ReadExactly(new Span<byte>((void*)Content, Size));
}

/// <summary>
Expand Down
26 changes: 2 additions & 24 deletions sources/core/Stride.Core/Diagnostics/ILogger.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Stride.Core.Diagnostics;

#nullable enable

/// <summary>
/// Extensions for <see cref="ILogger"/>.
/// </summary>
Expand All @@ -19,11 +21,7 @@ public static class LoggerExtensions
/// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
public static void Verbose(this ILogger logger, string message, Exception? exception, CallerInfo? callerInfo = null)
{
#if NET7_0_OR_GREATER
ArgumentNullException.ThrowIfNull(logger);
#else
if (logger is null) throw new ArgumentNullException(nameof(logger));
#endif // NET7_0_OR_GREATER
logger.Log(new LogMessage(logger.Module, LogMessageType.Verbose, message, exception, callerInfo));
}

Expand All @@ -46,11 +44,7 @@ public static void Verbose(this ILogger logger, string message, CallerInfo? call
/// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
public static void Debug(this ILogger logger, string message, Exception? exception, CallerInfo? callerInfo = null)
{
#if NET7_0_OR_GREATER
ArgumentNullException.ThrowIfNull(logger);
#else
if (logger is null) throw new ArgumentNullException(nameof(logger));
#endif // NET7_0_OR_GREATER
logger.Log(new LogMessage(logger.Module, LogMessageType.Debug, message, exception, callerInfo));
}

Expand All @@ -73,11 +67,7 @@ public static void Debug(this ILogger logger, string message, CallerInfo? caller
/// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
public static void Info(this ILogger logger, string message, Exception? exception, CallerInfo? callerInfo = null)
{
#if NET7_0_OR_GREATER
ArgumentNullException.ThrowIfNull(logger);
#else
if (logger is null) throw new ArgumentNullException(nameof(logger));
#endif // NET7_0_OR_GREATER
logger.Log(new LogMessage(logger.Module, LogMessageType.Info, message, exception, callerInfo));
}

Expand All @@ -100,11 +90,7 @@ public static void Info(this ILogger logger, string message, CallerInfo? callerI
/// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
public static void Warning(this ILogger logger, string message, Exception? exception, CallerInfo? callerInfo = null)
{
#if NET7_0_OR_GREATER
ArgumentNullException.ThrowIfNull(logger);
#else
if (logger is null) throw new ArgumentNullException(nameof(logger));
#endif // NET7_0_OR_GREATER
logger.Log(new LogMessage(logger.Module, LogMessageType.Warning, message, exception, callerInfo));
}

Expand All @@ -127,11 +113,7 @@ public static void Warning(this ILogger logger, string message, CallerInfo? call
/// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
public static void Error(this ILogger logger, string message, Exception? exception, CallerInfo? callerInfo = null)
{
#if NET7_0_OR_GREATER
ArgumentNullException.ThrowIfNull(logger);
#else
if (logger is null) throw new ArgumentNullException(nameof(logger));
#endif // NET7_0_OR_GREATER
logger.Log(new LogMessage(logger.Module, LogMessageType.Error, message, exception, callerInfo));
}

Expand All @@ -154,11 +136,7 @@ public static void Error(this ILogger logger, string message, CallerInfo? caller
/// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
public static void Fatal(this ILogger logger, string message, Exception? exception, CallerInfo? callerInfo = null)
{
#if NET7_0_OR_GREATER
ArgumentNullException.ThrowIfNull(logger);
#else
if (logger is null) throw new ArgumentNullException(nameof(logger));
#endif // NET7_0_OR_GREATER
logger.Log(new LogMessage(logger.Module, LogMessageType.Fatal, message, exception, callerInfo));
}

Expand Down
6 changes: 2 additions & 4 deletions sources/core/Stride.Core/Diagnostics/ILogger.Extensions.tt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Stride.Core.Diagnostics;

#nullable enable

/// <summary>
/// Extensions for <see cref="ILogger"/>.
/// </summary>
Expand All @@ -26,11 +28,7 @@ public static class LoggerExtensions
/// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
public static void <#= name #>(this ILogger logger, string message, Exception? exception, CallerInfo? callerInfo = null)
{
#if NET7_0_OR_GREATER
ArgumentNullException.ThrowIfNull(logger);
#else
if (logger is null) throw new ArgumentNullException(nameof(logger));
#endif // NET7_0_OR_GREATER
logger.Log(new LogMessage(logger.Module, LogMessageType.<#= name #>, message, exception, callerInfo));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public override unsafe void Serialize(ref T[] array, ArchiveMode mode, Serializa
{
var span = MemoryMarshal.Cast<T, byte>(array.AsSpan());
if (mode == ArchiveMode.Deserialize)
stream.UnderlyingStream.Read(span);
stream.UnderlyingStream.ReadExactly(span);
else if (mode == ArchiveMode.Serialize)
stream.UnderlyingStream.Write(span);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private async Task Update()
if (game.Input.IsKeyPressed(SceneEditorSettings.SwitchGizmo.GetValue()))
{
var current = activeTransformation;
var next = (int)(current + 1) % Enum.GetValues(typeof(Transformation)).Length;
var next = (int)(current + 1) % Enum.GetValues<Transformation>().Length;
await editor.Dispatcher.InvokeAsync(() => editor.Transform.ActiveTransformation = (Transformation)next);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private async Task<AssemblyChangedEvent> FileChangeTransformation(FileEvent e)
{
using (var streamReader = new StreamReader(File.Open(changedFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8, true))
{
source = streamReader.ReadToEnd();
source = await streamReader.ReadToEndAsync();
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private async Task TriggerBackgroundCompilation()
SemanticModel = compilation.GetSemanticModel(syntaxTree);

// Compute list of overridable methods
var type = SemanticModel.GetDeclaredSymbol(syntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>().FirstOrDefault());
var type = SemanticModel.GetDeclaredSymbol((await syntaxTree.GetRootAsync()).DescendantNodes().OfType<ClassDeclarationSyntax>().FirstOrDefault());

// Note: Logic taken from Roslyn AbstractOverrideCompletionProvider
var overridableMethodsCurrentType = new List<ISymbol>();
Expand Down Expand Up @@ -123,7 +123,7 @@ private async Task TriggerBackgroundCompilation()

// Find the syntax node that generated this diagnostic
var sourceSpan = diagnostic.Location.SourceSpan;
var node = compileResult.SyntaxTree.GetRoot().FindNode(sourceSpan);
var node = (await compileResult.SyntaxTree.GetRootAsync()).FindNode(sourceSpan);

// Find which block or link generated it
// Go through parent recursively until we find one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ private void GenerateSymbolSearchValues(Compilation latestCompilation, Cancellat
foreach (var assembly in GetAssemblies(latestCompilation, cancellationToken)
.OrderBy(assembly =>
{
if (assembly == latestCompilation.Assembly)
if (SymbolEqualityComparer.Default.Equals(assembly, latestCompilation.Assembly))
return 0;

if (assembly.Name.Contains("Stride"))
Expand All @@ -471,11 +471,11 @@ private void GenerateSymbolSearchValues(Compilation latestCompilation, Cancellat

// List types that are either public or part of current assembly
foreach (var type in GetAllTypes(assembly, cancellationToken)
.Where(type => type.DeclaredAccessibility != RoslynAccessibility.Private || type.ContainingAssembly == latestCompilation.Assembly))
.Where(type => type.DeclaredAccessibility != RoslynAccessibility.Private || SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, latestCompilation.Assembly)))
{
// List methods
foreach (var method in type.GetMembers().OfType<IMethodSymbol>()
.Where(member => member.DeclaredAccessibility != RoslynAccessibility.Private || type.ContainingAssembly == latestCompilation.Assembly))
.Where(member => member.DeclaredAccessibility != RoslynAccessibility.Private || SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, latestCompilation.Assembly)))
{
// Ignore .ctor, property getter/setter, events, etc...
if (method.MethodKind != MethodKind.Ordinary
Expand Down Expand Up @@ -522,7 +522,7 @@ private static IEnumerable<IAssemblySymbol> GetAssemblies(
CancellationToken cancellationToken)
{
var stack = new Stack<IAssemblySymbol>();
var processedAssemblies = new HashSet<IAssemblySymbol>();
var processedAssemblies = new HashSet<IAssemblySymbol>(SymbolEqualityComparer.Default);

processedAssemblies.Add(compilation.Assembly);
stack.Push(compilation.Assembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected override IEnumerable<AssetItem> CreateAssets(AssetTemplateGeneratorPar
scriptContent = scriptContent.Replace("##Namespace##", parameters.Namespace);
scriptContent = scriptContent.Replace("##Scriptname##", location.GetFileNameWithoutExtension());

var asset = (ScriptSourceFileAsset)ObjectFactoryRegistry.NewInstance(typeof(ScriptSourceFileAsset));
var asset = ObjectFactoryRegistry.NewInstance<ScriptSourceFileAsset>();
asset.Id = SourceCodeAsset.GenerateIdFromLocation(parameters.Package.Meta.Name, location);
asset.Text = scriptContent;
yield return new AssetItem(location, asset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected override async Task UpdateAssetFromSource(Logger logger)
document = workspace.GetDocument(DocumentId.Result);

// Set new text
TextDocument.Text = document.GetTextAsync().Result.ToString();
TextDocument.Text = (await document.GetTextAsync()).ToString();

// Update dirty state
hasExternalChanges = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ private void Paste([NotNull] Asset asset, string copiedText, Type deserializedTy
var result = service.DeserializeCopiedData(copiedText, asset, expectedType);
Assert.NotNull(result);
Assert.NotNull(result.Items);
Assert.Equal(1, result.Items.Count);
Assert.Single(result.Items);

var item = result.Items[0];
Assert.NotNull(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void NotifyBackgroundJobFinished(int token)
if (CurrentJob == job)
{
job = null;
foreach (JobPriority priority in Enum.GetValues(typeof(JobPriority)).Cast<JobPriority>().Reverse())
foreach (JobPriority priority in Enum.GetValues<JobPriority>().Cast<JobPriority>().Reverse())
{
var nextJob = jobList.LastOrDefault(x => x.Value.Priority == priority).Value;
if (nextJob != null)
Expand Down
Loading
Loading