diff --git a/src/Stl.Fusion.Blazor/BlazorModeHelper.cs b/src/Stl.Fusion.Blazor/BlazorModeHelper.cs index 644a2c4f1..0fed039bf 100644 --- a/src/Stl.Fusion.Blazor/BlazorModeHelper.cs +++ b/src/Stl.Fusion.Blazor/BlazorModeHelper.cs @@ -6,7 +6,7 @@ namespace Stl.Fusion.Blazor; public class BlazorModeHelper(NavigationManager navigator) { - public static bool IsBlazorServer { get; } = OSInfo.Kind != OSKind.WebAssembly; + public static readonly bool IsBlazorServer = OSInfo.Kind != OSKind.WebAssembly; protected NavigationManager Navigator { get; } = navigator; diff --git a/src/Stl.Fusion.Blazor/ParameterComparison/DefaultParameterComparer.cs b/src/Stl.Fusion.Blazor/ParameterComparison/DefaultParameterComparer.cs index 38d3bd5ca..ba38e9985 100644 --- a/src/Stl.Fusion.Blazor/ParameterComparison/DefaultParameterComparer.cs +++ b/src/Stl.Fusion.Blazor/ParameterComparison/DefaultParameterComparer.cs @@ -8,7 +8,7 @@ public class DefaultParameterComparer : ParameterComparer .GetInterfaces() .Single(x => Equals(x.Name, "IEventCallback")); - public static ParameterComparer Instance { get; } = new DefaultParameterComparer(); + public static ParameterComparer Instance { get; set; } = new DefaultParameterComparer(); // Mostly copied from Microsoft.AspNetCore.Components.ChangeDetection public override bool AreEqual(object? oldValue, object? newValue) diff --git a/src/Stl.Fusion.EntityFramework/DbHints.cs b/src/Stl.Fusion.EntityFramework/DbHints.cs index bf3a33595..9d42c174e 100644 --- a/src/Stl.Fusion.EntityFramework/DbHints.cs +++ b/src/Stl.Fusion.EntityFramework/DbHints.cs @@ -4,16 +4,16 @@ public abstract record DbHint(Symbol Value); public record DbLockingHint(Symbol Value) : DbHint(Value) { - public static DbLockingHint KeyShare { get; } = new(nameof(KeyShare)); - public static DbLockingHint Share { get; } = new(nameof(Share)); - public static DbLockingHint NoKeyUpdate { get; } = new(nameof(NoKeyUpdate)); - public static DbLockingHint Update { get; } = new(nameof(Update)); + public static readonly DbLockingHint KeyShare = new(nameof(KeyShare)); + public static readonly DbLockingHint Share = new(nameof(Share)); + public static readonly DbLockingHint NoKeyUpdate = new(nameof(NoKeyUpdate)); + public static readonly DbLockingHint Update = new(nameof(Update)); } public record DbWaitHint(Symbol Value) : DbHint(Value) { - public static DbLockingHint NoWait { get; } = new(nameof(NoWait)); - public static DbLockingHint SkipLocked { get; } = new(nameof(SkipLocked)); + public static readonly DbLockingHint NoWait = new(nameof(NoWait)); + public static readonly DbLockingHint SkipLocked = new(nameof(SkipLocked)); } public record DbCustomHint(Symbol Value) : DbHint(Value); diff --git a/src/Stl.Fusion.Ext.Contracts/Authentication/UserIdentity.cs b/src/Stl.Fusion.Ext.Contracts/Authentication/UserIdentity.cs index f31baded5..54ac14ada 100644 --- a/src/Stl.Fusion.Ext.Contracts/Authentication/UserIdentity.cs +++ b/src/Stl.Fusion.Ext.Contracts/Authentication/UserIdentity.cs @@ -8,7 +8,7 @@ namespace Stl.Fusion.Authentication; private static readonly ListFormat IdFormat = ListFormat.SlashSeparated; public static readonly UserIdentity None; - public static string DefaultSchema { get; } = "Default"; + public static string DefaultSchema { get; set; } = "Default"; [DataMember(Order = 0), MemoryPackOrder(0)] public Symbol Id { get; } diff --git a/src/Stl.Fusion.Ext.Services/Extensions/KeyValueStoreExt.cs b/src/Stl.Fusion.Ext.Services/Extensions/KeyValueStoreExt.cs index 364fcea39..41e4f799c 100644 --- a/src/Stl.Fusion.Ext.Services/Extensions/KeyValueStoreExt.cs +++ b/src/Stl.Fusion.Ext.Services/Extensions/KeyValueStoreExt.cs @@ -2,7 +2,7 @@ namespace Stl.Fusion.Extensions; public static class KeyValueStoreExt { - public static ListFormat ListFormat { get; } = ListFormat.SlashSeparated; + public static ListFormat ListFormat { get; set; } = ListFormat.SlashSeparated; public static char Delimiter => ListFormat.Delimiter; // Set diff --git a/src/Stl.Fusion/Session/Session.cs b/src/Stl.Fusion/Session/Session.cs index 813ad7b8d..eaf956a81 100644 --- a/src/Stl.Fusion/Session/Session.cs +++ b/src/Stl.Fusion/Session/Session.cs @@ -14,7 +14,7 @@ public sealed partial class Session : IHasId, IRequirementTarget, IEquatable, IConvertibleTo, IConvertibleTo, IHasJsonCompatibleToString { - public static Session Default { get; } = new("~"); + public static readonly Session Default = new("~"); public static SessionFactory Factory { get; set; } = DefaultSessionFactory.New(); public static SessionValidator Validator { get; set; } = session => !session.IsDefault(); diff --git a/src/Stl.Interception/ArgumentList-Generated.cs b/src/Stl.Interception/ArgumentList-Generated.cs index 6c3d20f1a..a56ca582b 100644 --- a/src/Stl.Interception/ArgumentList-Generated.cs +++ b/src/Stl.Interception/ArgumentList-Generated.cs @@ -1,4 +1,4 @@ -// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable MemberCanBePrivate.Global // ReSharper disable ArrangeConstructorOrDestructorBody using Cysharp.Text; @@ -10,7 +10,7 @@ namespace Stl.Interception; public abstract partial record ArgumentList { - public static ImmutableArray Types { get; } = ImmutableArray.Create(new [] { + public static readonly ImmutableArray Types = ImmutableArray.Create(new [] { typeof(ArgumentList0), typeof(ArgumentList<>), typeof(ArgumentList<, >), diff --git a/src/Stl.Interception/ArgumentList-Generated.tt b/src/Stl.Interception/ArgumentList-Generated.tt index f99971ead..11cf8bc12 100644 --- a/src/Stl.Interception/ArgumentList-Generated.tt +++ b/src/Stl.Interception/ArgumentList-Generated.tt @@ -49,7 +49,7 @@ namespace Stl.Interception; public abstract partial record ArgumentList { - public static ImmutableArray Types { get; } = ImmutableArray.Create(new [] { + public static readonly ImmutableArray Types = ImmutableArray.Create(new [] { typeof(ArgumentList0), <# for (var itemCount = 1; itemCount <= maxItemCount; itemCount++) { #> diff --git a/src/Stl.Interception/ArgumentList.cs b/src/Stl.Interception/ArgumentList.cs index d0592d095..3f10c8858 100644 --- a/src/Stl.Interception/ArgumentList.cs +++ b/src/Stl.Interception/ArgumentList.cs @@ -6,7 +6,7 @@ public abstract partial record ArgumentList { protected static readonly ConcurrentDictionary<(Type, MethodInfo), Func> InvokerCache = new(); - public static ArgumentList Empty { get; } = new ArgumentList0(); + public static readonly ArgumentList Empty = new ArgumentList0(); [JsonIgnore, Newtonsoft.Json.JsonIgnore, IgnoreDataMember, MemoryPackIgnore] public abstract int Length { get; } diff --git a/src/Stl.Interception/TypeViewFactory.cs b/src/Stl.Interception/TypeViewFactory.cs index e22241840..580797c3d 100644 --- a/src/Stl.Interception/TypeViewFactory.cs +++ b/src/Stl.Interception/TypeViewFactory.cs @@ -9,15 +9,12 @@ TypeViewFactory For() where TView : class; } -public class TypeViewFactory : ITypeViewFactory +public class TypeViewFactory(TypeViewInterceptor interceptor) : ITypeViewFactory { - public static ITypeViewFactory Default { get; } = + public static ITypeViewFactory Default { get; set; } = new TypeViewFactory(new TypeViewInterceptor(DependencyInjection.ServiceProviderExt.Empty)); - protected Interceptor Interceptor { get; } - - public TypeViewFactory(TypeViewInterceptor interceptor) - => Interceptor = interceptor; + protected Interceptor Interceptor { get; } = interceptor; public object CreateView(object implementation, Type viewType) { diff --git a/src/Stl.Plugins/Metadata/PluginSetInfo.cs b/src/Stl.Plugins/Metadata/PluginSetInfo.cs index 341e09e2c..69f5020ee 100644 --- a/src/Stl.Plugins/Metadata/PluginSetInfo.cs +++ b/src/Stl.Plugins/Metadata/PluginSetInfo.cs @@ -2,7 +2,7 @@ namespace Stl.Plugins.Metadata; public class PluginSetInfo { - public static PluginSetInfo Empty { get; } = new( + public static readonly PluginSetInfo Empty = new( ImmutableDictionary.Empty, ImmutableDictionary>.Empty, ImmutableDictionary>.Empty); @@ -81,7 +81,7 @@ public override string ToString() // Private methods - // This method is used instead of .ToHashSet to eliminate #if NETFRAMEWORK + // This method is used instead of .ToHashSet to eliminate #if NETFRAMEWORK private static HashSet ToHashSet(IEnumerable source) => new(source); diff --git a/src/Stl.Plugins/PluginInfoProvider.cs b/src/Stl.Plugins/PluginInfoProvider.cs index 86d5a0f2b..c42a99c44 100644 --- a/src/Stl.Plugins/PluginInfoProvider.cs +++ b/src/Stl.Plugins/PluginInfoProvider.cs @@ -10,7 +10,7 @@ public interface IPluginInfoProvider /// public class Query { - public static Query Instance { get; } = new(); + public static readonly Query Instance = new(); } ImmutableHashSet GetDependencies(Type pluginType); diff --git a/src/Stl.Rpc/WebSockets/WebSocketChannel.cs b/src/Stl.Rpc/WebSockets/WebSocketChannel.cs index 2cad013e4..7d234dd1a 100644 --- a/src/Stl.Rpc/WebSockets/WebSocketChannel.cs +++ b/src/Stl.Rpc/WebSockets/WebSocketChannel.cs @@ -12,7 +12,7 @@ public sealed class WebSocketChannel : Channel { public record Options { - public static Options Default { get; } = new(); + public static readonly Options Default = new(); public bool OwnsWebSocket { get; init; } = true; public int WriteFrameSize { get; init; } = 4400; diff --git a/src/Stl/Async/ValueTaskExt.cs b/src/Stl/Async/ValueTaskExt.cs index a14340960..3ff613c0d 100644 --- a/src/Stl/Async/ValueTaskExt.cs +++ b/src/Stl/Async/ValueTaskExt.cs @@ -6,11 +6,11 @@ namespace Stl.Async; public static class ValueTaskExt { - public static ValueTask NeverEndingTask { get; } = TaskExt.NeverEndingTask.ToValueTask(); - public static ValueTask NeverEndingUnitTask { get; } = TaskExt.NeverEndingUnitTask.ToValueTask(); - public static ValueTask CompletedTask { get; } = Task.CompletedTask.ToValueTask(); - public static ValueTask TrueTask { get; } = FromResult(true); - public static ValueTask FalseTask { get; } = FromResult(false); + public static readonly ValueTask NeverEndingTask = TaskExt.NeverEndingTask.ToValueTask(); + public static readonly ValueTask NeverEndingUnitTask = TaskExt.NeverEndingUnitTask.ToValueTask(); + public static readonly ValueTask CompletedTask = Task.CompletedTask.ToValueTask(); + public static readonly ValueTask TrueTask = FromResult(true); + public static readonly ValueTask FalseTask = FromResult(false); public static ValueTask FromResult(T value) => new(value); public static ValueTask FromException(Exception error) => new(Task.FromException(error)); diff --git a/src/Stl/Collections/Slim/ReferenceEqualityComparer.cs b/src/Stl/Collections/Slim/ReferenceEqualityComparer.cs index 6236e91a6..382ce49ee 100644 --- a/src/Stl/Collections/Slim/ReferenceEqualityComparer.cs +++ b/src/Stl/Collections/Slim/ReferenceEqualityComparer.cs @@ -3,7 +3,8 @@ namespace Stl.Collections.Slim; public sealed class ReferenceEqualityComparer : IEqualityComparer where T : class { - public static ReferenceEqualityComparer Instance { get; } = new(); + public static readonly ReferenceEqualityComparer Instance = new(); + public bool Equals(T? x, T? y) => ReferenceEquals(x, y); public int GetHashCode(T obj) => RuntimeHelpers.GetHashCode(obj); } diff --git a/src/Stl/Concurrency/GCHandlePool.cs b/src/Stl/Concurrency/GCHandlePool.cs index c333859a5..d5c76f923 100644 --- a/src/Stl/Concurrency/GCHandlePool.cs +++ b/src/Stl/Concurrency/GCHandlePool.cs @@ -4,7 +4,7 @@ public sealed class GCHandlePool(GCHandlePool.Options settings) : IDisposable { public record Options { - public static Options Default { get; } = new(); + public static readonly Options Default = new(); public int Capacity { get; init; } = 1024; public GCHandleType HandleType { get; init; } = GCHandleType.Weak; diff --git a/src/Stl/Conversion/Internal/CastToBaseConverter.cs b/src/Stl/Conversion/Internal/CastToBaseConverter.cs index bdd95b1fb..d5f4a84da 100644 --- a/src/Stl/Conversion/Internal/CastToBaseConverter.cs +++ b/src/Stl/Conversion/Internal/CastToBaseConverter.cs @@ -3,7 +3,7 @@ namespace Stl.Conversion.Internal; public class CastToBaseConverter : Converter where TSource : TTarget { - public static CastToBaseConverter Instance { get; } = new(); + public static readonly CastToBaseConverter Instance = new(); public override TTarget Convert(TSource source) => source; diff --git a/src/Stl/Conversion/Internal/CastToDescendantConverter.cs b/src/Stl/Conversion/Internal/CastToDescendantConverter.cs index d9c318b23..dc9e4ff3d 100644 --- a/src/Stl/Conversion/Internal/CastToDescendantConverter.cs +++ b/src/Stl/Conversion/Internal/CastToDescendantConverter.cs @@ -3,7 +3,7 @@ namespace Stl.Conversion.Internal; public class CastToDescendantConverter : Converter where TTarget : TSource { - public static CastToDescendantConverter Instance { get; } = new(); + public static readonly CastToDescendantConverter Instance = new(); public override TTarget Convert(TSource source) => (TTarget) source!; diff --git a/src/Stl/Conversion/Internal/DefaultSourceConverterProvider.cs b/src/Stl/Conversion/Internal/DefaultSourceConverterProvider.cs index de2a35bf4..d00852c40 100644 --- a/src/Stl/Conversion/Internal/DefaultSourceConverterProvider.cs +++ b/src/Stl/Conversion/Internal/DefaultSourceConverterProvider.cs @@ -23,22 +23,22 @@ protected virtual Converter GetConverter() // 0. Can we simply cast to base / descendant? if (tTarget.IsAssignableFrom(tSource)) { - var pInstance = + var fInstance = typeof(CastToBaseConverter<,>) .MakeGenericType(tSource, tTarget) - .GetProperty( + .GetField( nameof(CastToBaseConverter.Instance), BindingFlags.Static | BindingFlags.Public); - return (Converter) pInstance!.GetValue(null)!; + return (Converter) fInstance!.GetValue(null)!; } if (tSource.IsAssignableFrom(tTarget)) { - var pInstance = + var fInstance = typeof(CastToDescendantConverter<,>) .MakeGenericType(tSource, tTarget) - .GetProperty( + .GetField( nameof(CastToDescendantConverter.Instance), BindingFlags.Static | BindingFlags.Public); - return (Converter) pInstance!.GetValue(null)!; + return (Converter) fInstance!.GetValue(null)!; } // 1. Is there IConverter<,> service? diff --git a/src/Stl/DependencyInjection/ServiceProviderExt.cs b/src/Stl/DependencyInjection/ServiceProviderExt.cs index 8ebd50c7f..5b2202d2f 100644 --- a/src/Stl/DependencyInjection/ServiceProviderExt.cs +++ b/src/Stl/DependencyInjection/ServiceProviderExt.cs @@ -2,7 +2,7 @@ namespace Stl.DependencyInjection; public static class ServiceProviderExt { - public static IServiceProvider Empty { get; } = new ServiceCollection().BuildServiceProvider(); + public static readonly IServiceProvider Empty = new ServiceCollection().BuildServiceProvider(); // Logging extensions diff --git a/src/Stl/Diagnostics/ActivitySourceExt.cs b/src/Stl/Diagnostics/ActivitySourceExt.cs index 951103f92..d3356c040 100644 --- a/src/Stl/Diagnostics/ActivitySourceExt.cs +++ b/src/Stl/Diagnostics/ActivitySourceExt.cs @@ -4,7 +4,7 @@ namespace Stl.Diagnostics; public static class ActivitySourceExt { - public static ActivitySource Unknown { get; } = new(""); + public static readonly ActivitySource Unknown = new(""); public static Activity? StartActivity( this ActivitySource activitySource, diff --git a/src/Stl/Diagnostics/MeterExt.cs b/src/Stl/Diagnostics/MeterExt.cs index 060f77c42..d96d46022 100644 --- a/src/Stl/Diagnostics/MeterExt.cs +++ b/src/Stl/Diagnostics/MeterExt.cs @@ -4,5 +4,5 @@ namespace Stl.Diagnostics; public static class MeterExt { - public static Meter Unknown { get; } = new(""); + public static readonly Meter Unknown = new(""); } diff --git a/src/Stl/Diagnostics/Samplers.cs b/src/Stl/Diagnostics/Samplers.cs index 26ade2051..b9145639e 100644 --- a/src/Stl/Diagnostics/Samplers.cs +++ b/src/Stl/Diagnostics/Samplers.cs @@ -10,9 +10,9 @@ public sealed record Sampler( Func Duplicate) { #pragma warning disable CS8603 - public static Sampler Always { get; } = + public static readonly Sampler Always = new(nameof(Always), 1, static () => true, () => Always); - public static Sampler Never { get; } = + public static readonly Sampler Never = new(nameof(Never), 0, static () => false, () => Never); #pragma warning restore CS8603 diff --git a/src/Stl/IO/FileExt.cs b/src/Stl/IO/FileExt.cs index e1035d450..e8bc13ffb 100644 --- a/src/Stl/IO/FileExt.cs +++ b/src/Stl/IO/FileExt.cs @@ -4,8 +4,8 @@ namespace Stl.IO; public static class FileExt { - public static Encoding DefaultReadEncoding { get; } = Encoding.UTF8; - public static Encoding DefaultWriteEncoding { get; } = new UTF8Encoding(false, true); + public static readonly Encoding DefaultReadEncoding = Encoding.UTF8; + public static readonly Encoding DefaultWriteEncoding = new UTF8Encoding(false, true); public static Task WriteText(string path, string? contents, CancellationToken cancellationToken = default) => WriteText(path, contents, null, cancellationToken); diff --git a/src/Stl/Multitenancy/Tenant.cs b/src/Stl/Multitenancy/Tenant.cs index 0bbab9471..0df0fd12d 100644 --- a/src/Stl/Multitenancy/Tenant.cs +++ b/src/Stl/Multitenancy/Tenant.cs @@ -3,8 +3,8 @@ namespace Stl.Multitenancy; [DataContract, MemoryPackable(GenerateType.VersionTolerant)] public partial record Tenant : IHasId { - public static Tenant Default { get; } = new(Symbol.Empty, "The only tenant", ""); - public static Tenant Dummy { get; } = new("*", "Example tenant", "__example"); + public static readonly Tenant Default = new(Symbol.Empty, "The only tenant", ""); + public static readonly Tenant Dummy = new("*", "Example tenant", "__example"); [DataMember, MemoryPackOrder(0)] public Symbol Id { get; init; } = Symbol.Empty; diff --git a/src/Stl/OS/DisplayInfo.cs b/src/Stl/OS/DisplayInfo.cs deleted file mode 100644 index d2037bfcd..000000000 --- a/src/Stl/OS/DisplayInfo.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Diagnostics; -using System.Drawing; -using System.Globalization; - -namespace Stl.OS; - -public static class DisplayInfo -{ - public static Rectangle? PrimaryDisplayDimensions { get; } - - static DisplayInfo() - { - PrimaryDisplayDimensions = null; - try { - switch (OSInfo.Kind) { - case OSKind.Windows: - var p = new Process() { - StartInfo = new ProcessStartInfo() { - FileName = "cmd.exe", - Arguments = "/c wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution", - UseShellExecute = false, - RedirectStandardOutput = true, - CreateNoWindow = true - } - }; - p.Start(); - p.WaitForExit(); - var wh = p.StandardOutput.ReadToEnd().TrimEnd() - .Split("\r\n").Last() - .Split(" ", StringSplitOptions.RemoveEmptyEntries); - var w = int.Parse(wh[0], NumberStyles.Integer, CultureInfo.InvariantCulture); - var h = int.Parse(wh[1], NumberStyles.Integer, CultureInfo.InvariantCulture); - PrimaryDisplayDimensions = new Rectangle(0, 0, w, h); - break; - } - } - catch { - PrimaryDisplayDimensions = null; - } - } -} diff --git a/src/Stl/OS/HardwareInfo.cs b/src/Stl/OS/HardwareInfo.cs index a4facdd28..a617105e1 100644 --- a/src/Stl/OS/HardwareInfo.cs +++ b/src/Stl/OS/HardwareInfo.cs @@ -10,7 +10,7 @@ public static class HardwareInfo // Environment.TickCount is negative in WebAssembly @ startup Environment.TickCount - (RefreshIntervalTicks << 1); - public static bool IsSingleThreaded { get; } = OSInfo.IsWebAssembly; + public static readonly bool IsSingleThreaded = OSInfo.IsWebAssembly; public static int ProcessorCount { get { diff --git a/src/Stl/Requirement.cs b/src/Stl/Requirement.cs index 04afec1cb..857f69220 100644 --- a/src/Stl/Requirement.cs +++ b/src/Stl/Requirement.cs @@ -13,15 +13,15 @@ public abstract record Requirement public abstract object CheckUntyped([NotNull] object? value); #endif - public static FuncRequirement New(ExceptionBuilder exceptionBuilder, Func validator) + public static FuncRequirement New(ExceptionBuilder exceptionBuilder, Func validator) => new(exceptionBuilder, validator); - public static FuncRequirement New(Func validator) + public static FuncRequirement New(Func validator) => new(validator); } public abstract record Requirement : Requirement { - private const string MustExistPropertyName = "MustExist"; + private const string MustExistFieldOrPropertyName = "MustExist"; // ReSharper disable once StaticMemberInGenericType private static readonly object MustExistLock = new(); private static volatile Requirement? _mustExist; @@ -36,10 +36,10 @@ public static Requirement MustExist { var type = typeof(T); var result = type - .GetProperty(MustExistPropertyName, BindingFlags.Public | BindingFlags.Static) + .GetField(MustExistFieldOrPropertyName, BindingFlags.Public | BindingFlags.Static) ?.GetValue(null) as Requirement; result ??= type - .GetField(MustExistPropertyName, BindingFlags.Public | BindingFlags.Static) + .GetProperty(MustExistFieldOrPropertyName, BindingFlags.Public | BindingFlags.Static) ?.GetValue(null) as Requirement; result ??= MustExistRequirement.Default; return _mustExist = result; diff --git a/src/Stl/Requirements/ExceptionBuilder.cs b/src/Stl/Requirements/ExceptionBuilder.cs index 293b307d4..a66783636 100644 --- a/src/Stl/Requirements/ExceptionBuilder.cs +++ b/src/Stl/Requirements/ExceptionBuilder.cs @@ -5,8 +5,10 @@ namespace Stl.Requirements; public readonly record struct ExceptionBuilder { - public static Func DefaultExceptionFactory { get; } = message => new ValidationException(message); - public static string DefaultMessageTemplate { get; } = "{0}: validation failed."; + public static Func DefaultExceptionFactory { get; set; } + = message => new ValidationException(message); + public static string DefaultMessageTemplate { get; set; } + = "{0}: validation failed."; public string? MessageTemplate { get; init; } public string? TargetName { get; init; } @@ -41,7 +43,7 @@ public Exception Build(TValue? value) string.Format(CultureInfo.InvariantCulture, message, targetName, value)), Func simple => simple.Invoke(), _ => DefaultExceptionFactory.Invoke( - string.Format(CultureInfo.InvariantCulture, message, targetName, value)), + string.Format(CultureInfo.InvariantCulture, message, targetName, value)), }; return exception; } diff --git a/src/Stl/Requirements/MustExistRequirement.cs b/src/Stl/Requirements/MustExistRequirement.cs index 6682bc2bc..cf8bad0eb 100644 --- a/src/Stl/Requirements/MustExistRequirement.cs +++ b/src/Stl/Requirements/MustExistRequirement.cs @@ -5,7 +5,7 @@ namespace Stl.Requirements; public record MustExistRequirement : CustomizableRequirementBase { - public static MustExistRequirement Default { get; } = new(); + public static readonly MustExistRequirement Default = new(); public MustExistRequirement() => ExceptionBuilder = new("'{0}' is not found.", message => new ValidationException(message)); diff --git a/src/Stl/Requirements/ServiceExceptionWrapper.cs b/src/Stl/Requirements/ServiceExceptionWrapper.cs index 7c738f500..d1438bd20 100644 --- a/src/Stl/Requirements/ServiceExceptionWrapper.cs +++ b/src/Stl/Requirements/ServiceExceptionWrapper.cs @@ -4,7 +4,7 @@ namespace Stl.Requirements; public record ServiceExceptionWrapper(Requirement BaseRequirement) : Requirement { - public static ServiceExceptionWrapper Default { get; } = + public static readonly ServiceExceptionWrapper Default = new(MustExistRequirement.Default); public override bool IsSatisfied(T? value) diff --git a/src/Stl/Serialization/ByteSerializer.cs b/src/Stl/Serialization/ByteSerializer.cs index 9688cfe17..55f6b022c 100644 --- a/src/Stl/Serialization/ByteSerializer.cs +++ b/src/Stl/Serialization/ByteSerializer.cs @@ -20,7 +20,7 @@ public static IByteSerializer NewAsymmetric(IByteSerializer reader, IByteSeriali public static class ByteSerializer { - public static IByteSerializer Default { get; } = ByteSerializer.Default.ToTyped(); + public static readonly IByteSerializer Default = ByteSerializer.Default.ToTyped(); public static readonly IByteSerializer None = NoneByteSerializer.Instance; public static readonly IByteSerializer Null = NullByteSerializer.Instance; diff --git a/src/Stl/Serialization/Internal/NoneByteSerializer.cs b/src/Stl/Serialization/Internal/NoneByteSerializer.cs index 5fed4f40c..37775185f 100644 --- a/src/Stl/Serialization/Internal/NoneByteSerializer.cs +++ b/src/Stl/Serialization/Internal/NoneByteSerializer.cs @@ -7,7 +7,7 @@ namespace Stl.Serialization.Internal; /// public sealed class NoneByteSerializer : IByteSerializer { - public static NoneByteSerializer Instance { get; } = new(); + public static readonly NoneByteSerializer Instance = new(); public object? Read(ReadOnlyMemory data, Type type, out int readLength) => throw Errors.NoSerializer(); @@ -24,7 +24,7 @@ public IByteSerializer ToTyped(Type? serializedType = null) /// public sealed class NoneByteSerializer : IByteSerializer { - public static NoneByteSerializer Instance { get; } = new(); + public static readonly NoneByteSerializer Instance = new(); public T Read(ReadOnlyMemory data, out int readLength) => throw Errors.NoSerializer(); diff --git a/src/Stl/Serialization/Internal/NoneTextSerializer.cs b/src/Stl/Serialization/Internal/NoneTextSerializer.cs index f9e8aa392..adf56f3fd 100644 --- a/src/Stl/Serialization/Internal/NoneTextSerializer.cs +++ b/src/Stl/Serialization/Internal/NoneTextSerializer.cs @@ -7,7 +7,7 @@ namespace Stl.Serialization.Internal; /// public sealed class NoneTextSerializer : ITextSerializer { - public static NoneTextSerializer Instance { get; } = new(); + public static readonly NoneTextSerializer Instance = new(); public bool PreferStringApi => false; @@ -36,7 +36,7 @@ public ITextSerializer ToTyped(Type? serializedType = null) /// public sealed class NoneTextSerializer : ITextSerializer { - public static NoneTextSerializer Instance { get; } = new(); + public static readonly NoneTextSerializer Instance = new(); public bool PreferStringApi => false; diff --git a/src/Stl/Serialization/Internal/NullByteSerializer.cs b/src/Stl/Serialization/Internal/NullByteSerializer.cs index 1b78679ab..62005b4bd 100644 --- a/src/Stl/Serialization/Internal/NullByteSerializer.cs +++ b/src/Stl/Serialization/Internal/NullByteSerializer.cs @@ -7,7 +7,7 @@ namespace Stl.Serialization.Internal; /// public sealed class NullByteSerializer : IByteSerializer { - public static NullByteSerializer Instance { get; } = new(); + public static readonly NullByteSerializer Instance = new(); public object? Read(ReadOnlyMemory data, Type type, out int readLength) { @@ -27,7 +27,7 @@ public IByteSerializer ToTyped(Type? serializedType = null) /// public sealed class NullByteSerializer : IByteSerializer { - public static NullByteSerializer Instance { get; } = new(); + public static readonly NullByteSerializer Instance = new(); public T Read(ReadOnlyMemory data, out int readLength) { diff --git a/src/Stl/Serialization/Internal/NullTextSerializer.cs b/src/Stl/Serialization/Internal/NullTextSerializer.cs index 9f9af6b33..15b1ff684 100644 --- a/src/Stl/Serialization/Internal/NullTextSerializer.cs +++ b/src/Stl/Serialization/Internal/NullTextSerializer.cs @@ -7,7 +7,7 @@ namespace Stl.Serialization.Internal; /// public sealed class NullTextSerializer : ITextSerializer { - public static NullTextSerializer Instance { get; } = new(); + public static readonly NullTextSerializer Instance = new(); public bool PreferStringApi => false; @@ -50,7 +50,7 @@ public ITextSerializer ToTyped(Type? serializedType = null) /// public sealed class NullTextSerializer : ITextSerializer { - public static NullTextSerializer Instance { get; } = new(); + public static readonly NullTextSerializer Instance = new(); public bool PreferStringApi => false; diff --git a/src/Stl/Serialization/TextSerializer.cs b/src/Stl/Serialization/TextSerializer.cs index d69544e92..0e96e259e 100644 --- a/src/Stl/Serialization/TextSerializer.cs +++ b/src/Stl/Serialization/TextSerializer.cs @@ -14,7 +14,7 @@ public static ITextSerializer NewAsymmetric(ITextSerializer reader, ITextSeriali public static class TextSerializer { - public static ITextSerializer Default { get; } = TextSerializer.Default.ToTyped(); + public static readonly ITextSerializer Default = TextSerializer.Default.ToTyped(); public static readonly ITextSerializer None = NoneTextSerializer.Instance; public static readonly ITextSerializer Null = NullTextSerializer.Instance; diff --git a/src/Stl/Time/TimerSet.cs b/src/Stl/Time/TimerSet.cs index 53e9341ef..c29a3403f 100644 --- a/src/Stl/Time/TimerSet.cs +++ b/src/Stl/Time/TimerSet.cs @@ -3,9 +3,7 @@ namespace Stl.Time; public record TimerSetOptions { public static readonly TimerSetOptions Default = new(); - - // ReSharper disable once StaticMemberInGenericType - public static TimeSpan MinQuanta { get; } = TimeSpan.FromMilliseconds(10); + public static readonly TimeSpan MinQuanta = TimeSpan.FromMilliseconds(10); public TimeSpan Quanta { get; init; } = TimeSpan.FromSeconds(1); public IMomentClock Clock { get; init; } = MomentClockSet.Default.CpuClock; diff --git a/tests/Stl.Fusion.Tests/Services/DisplayInfo.cs b/tests/Stl.Fusion.Tests/Services/DisplayInfo.cs new file mode 100644 index 000000000..b38b820ad --- /dev/null +++ b/tests/Stl.Fusion.Tests/Services/DisplayInfo.cs @@ -0,0 +1,41 @@ +using System.Drawing; +using System.Globalization; +using Stl.OS; + +namespace Stl.Fusion.Tests.Services; + +public static class DisplayInfo +{ + public static readonly Rectangle? PrimaryDisplayDimensions; + + static DisplayInfo() + { + PrimaryDisplayDimensions = null; + try { + switch (OSInfo.Kind) { + case OSKind.Windows: + var p = new Process() { + StartInfo = new ProcessStartInfo() { + FileName = "cmd.exe", + Arguments = "/c wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution", + UseShellExecute = false, + RedirectStandardOutput = true, + CreateNoWindow = true + } + }; + p.Start(); + p.WaitForExit(); + var wh = p.StandardOutput.ReadToEnd().TrimEnd() + .Split("\r\n").Last() + .Split(" ", StringSplitOptions.RemoveEmptyEntries); + var w = int.Parse(wh[0], NumberStyles.Integer, CultureInfo.InvariantCulture); + var h = int.Parse(wh[1], NumberStyles.Integer, CultureInfo.InvariantCulture); + PrimaryDisplayDimensions = new Rectangle(0, 0, w, h); + break; + } + } + catch { + PrimaryDisplayDimensions = null; + } + } +} diff --git a/tests/Stl.Fusion.Tests/Services/ScreenshotService.cs b/tests/Stl.Fusion.Tests/Services/ScreenshotService.cs index d73402c2a..4c190e304 100644 --- a/tests/Stl.Fusion.Tests/Services/ScreenshotService.cs +++ b/tests/Stl.Fusion.Tests/Services/ScreenshotService.cs @@ -1,7 +1,6 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; -using Stl.OS; namespace Stl.Fusion.Tests.Services; diff --git a/tests/Stl.Tests/CommandR/Services/Commands.cs b/tests/Stl.Tests/CommandR/Services/Commands.cs index 2e971db8b..98c02d129 100644 --- a/tests/Stl.Tests/CommandR/Services/Commands.cs +++ b/tests/Stl.Tests/CommandR/Services/Commands.cs @@ -19,7 +19,7 @@ public record DivCommand : ICommand public record RecSumCommand : ICommand { - public static AsyncLocal Tag { get; } = new(); + public static readonly AsyncLocal Tag = new(); public double[] Arguments { get; init; } = Array.Empty(); }