diff --git a/src/Snap.Hutao/Snap.Hutao.Test/BaseClassLibrary/TypeReflectionTest.cs b/src/Snap.Hutao/Snap.Hutao.Test/BaseClassLibrary/TypeReflectionTest.cs
index 42020e6d..668fc70a 100644
--- a/src/Snap.Hutao/Snap.Hutao.Test/BaseClassLibrary/TypeReflectionTest.cs
+++ b/src/Snap.Hutao/Snap.Hutao.Test/BaseClassLibrary/TypeReflectionTest.cs
@@ -1,5 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
+using System;
namespace Snap.Hutao.Test.BaseClassLibrary;
diff --git a/src/Snap.Hutao/Snap.Hutao.Test/BaseClassLibrary/UnsafeAccessorTest.cs b/src/Snap.Hutao/Snap.Hutao.Test/BaseClassLibrary/UnsafeAccessorTest.cs
index 28c7c74f..0019bdc8 100644
--- a/src/Snap.Hutao/Snap.Hutao.Test/BaseClassLibrary/UnsafeAccessorTest.cs
+++ b/src/Snap.Hutao/Snap.Hutao.Test/BaseClassLibrary/UnsafeAccessorTest.cs
@@ -16,7 +16,7 @@ public class UnsafeAccessorTest
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = "get_TestProperty")]
private static extern int InternalGetInterfaceProperty(ITestInterface instance);
- interface ITestInterface
+ internal interface ITestInterface
{
internal int TestProperty { get; }
}
diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Collection/AdvancedCollectionView/VectorChangedEventArgs.cs b/src/Snap.Hutao/Snap.Hutao/Control/Collection/AdvancedCollectionView/VectorChangedEventArgs.cs
index d0e1a439..c5cb362b 100644
--- a/src/Snap.Hutao/Snap.Hutao/Control/Collection/AdvancedCollectionView/VectorChangedEventArgs.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Control/Collection/AdvancedCollectionView/VectorChangedEventArgs.cs
@@ -7,7 +7,7 @@ namespace Snap.Hutao.Control.Collection.AdvancedCollectionView;
internal sealed class VectorChangedEventArgs : IVectorChangedEventArgs
{
- public VectorChangedEventArgs(CollectionChange cc, int index = -1, object item = null!)
+ public VectorChangedEventArgs(CollectionChange cc, int index = -1, object item = default!)
{
CollectionChange = cc;
Index = (uint)index;
diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Layout/WrapLayoutState.cs b/src/Snap.Hutao/Snap.Hutao/Control/Layout/WrapLayoutState.cs
index 4f18691a..5a25f9de 100644
--- a/src/Snap.Hutao/Snap.Hutao/Control/Layout/WrapLayoutState.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Control/Layout/WrapLayoutState.cs
@@ -25,10 +25,7 @@ internal sealed class WrapLayoutState
public WrapItem GetItemAt(int index)
{
- if (index < 0)
- {
- throw new IndexOutOfRangeException();
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(index);
if (index <= (items.Count - 1))
{
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/DatabaseCorruptedException.cs b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/DatabaseCorruptedException.cs
deleted file mode 100644
index f66043bf..00000000
--- a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/DatabaseCorruptedException.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (c) DGP Studio. All rights reserved.
-// Licensed under the MIT license.
-
-namespace Snap.Hutao.Core.ExceptionService;
-
-///
-/// 数据库损坏异常
-///
-[HighQuality]
-[Obsolete("Use HutaoException instead")]
-internal sealed class DatabaseCorruptedException : Exception
-{
- ///
- /// 构造一个新的用户数据损坏异常
- ///
- /// 消息
- /// 内部错误
- public DatabaseCorruptedException(string message, Exception? innerException)
- : base(SH.FormatCoreExceptionServiceDatabaseCorruptedMessage($"{message}\n{innerException?.Message}"), innerException)
- {
- }
-}
\ No newline at end of file
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/HutaoException.cs b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/HutaoException.cs
index 923a9481..e90e4b22 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/HutaoException.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/HutaoException.cs
@@ -1,6 +1,8 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
+using System.Runtime.CompilerServices;
+
namespace Snap.Hutao.Core.ExceptionService;
internal sealed class HutaoException : Exception
@@ -11,11 +13,13 @@ internal sealed class HutaoException : Exception
}
[DoesNotReturn]
+ [MethodImpl(MethodImplOptions.NoInlining)]
public static HutaoException Throw(string message, Exception? innerException = default)
{
throw new HutaoException(message, innerException);
}
+ [MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowIf([DoesNotReturnIf(true)] bool condition, string message, Exception? innerException = default)
{
if (condition)
@@ -24,6 +28,7 @@ internal sealed class HutaoException : Exception
}
}
+ [MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowIfNot([DoesNotReturnIf(false)] bool condition, string message, Exception? innerException = default)
{
if (!condition)
@@ -33,18 +38,28 @@ internal sealed class HutaoException : Exception
}
[DoesNotReturn]
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ public static ArgumentException Argument(string message, string? paramName)
+ {
+ throw new ArgumentException(message, paramName);
+ }
+
+ [DoesNotReturn]
+ [MethodImpl(MethodImplOptions.NoInlining)]
public static HutaoException GachaStatisticsInvalidItemId(uint id, Exception? innerException = default)
{
throw new HutaoException(SH.FormatServiceGachaStatisticsFactoryItemIdInvalid(id), innerException);
}
[DoesNotReturn]
+ [MethodImpl(MethodImplOptions.NoInlining)]
public static HutaoException UserdataCorrupted(string message, Exception? innerException = default)
{
throw new HutaoException(message, innerException);
}
[DoesNotReturn]
+ [MethodImpl(MethodImplOptions.NoInlining)]
public static InvalidCastException InvalidCast(string name, Exception? innerException = default)
{
string message = $"This instance of '{typeof(TFrom).FullName}' '{name}' doesn't implement '{typeof(TTo).FullName}'";
@@ -52,18 +67,21 @@ internal sealed class HutaoException : Exception
}
[DoesNotReturn]
+ [MethodImpl(MethodImplOptions.NoInlining)]
public static InvalidOperationException InvalidOperation(string message, Exception? innerException = default)
{
throw new InvalidOperationException(message, innerException);
}
[DoesNotReturn]
+ [MethodImpl(MethodImplOptions.NoInlining)]
public static NotSupportedException NotSupported(string? message = default, Exception? innerException = default)
{
throw new NotSupportedException(message, innerException);
}
[DoesNotReturn]
+ [MethodImpl(MethodImplOptions.NoInlining)]
public static OperationCanceledException OperationCanceled(string message, Exception? innerException = default)
{
throw new OperationCanceledException(message, innerException);
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/RuntimeEnvironmentException.cs b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/RuntimeEnvironmentException.cs
deleted file mode 100644
index a9c82957..00000000
--- a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/RuntimeEnvironmentException.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (c) DGP Studio. All rights reserved.
-// Licensed under the MIT license.
-
-namespace Snap.Hutao.Core.ExceptionService;
-
-///
-/// 运行环境异常
-/// 用户的计算机中的某些设置不符合要求
-///
-[HighQuality]
-[Obsolete("Use HutaoException instead")]
-internal sealed class RuntimeEnvironmentException : Exception
-{
- ///
- /// 构造一个新的运行环境异常
- ///
- /// 消息
- /// 内部错误
- public RuntimeEnvironmentException(string message, Exception? innerException)
- : base($"{message}\n{innerException?.Message}", innerException)
- {
- }
-}
\ No newline at end of file
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/ThrowHelper.cs b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/ThrowHelper.cs
index 38b1fec1..5cdf3e36 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/ThrowHelper.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/ThrowHelper.cs
@@ -1,9 +1,6 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
-using Snap.Hutao.Service.Game;
-using Snap.Hutao.Service.Game.Package;
-using System.IO;
using System.Runtime.CompilerServices;
namespace Snap.Hutao.Core.ExceptionService;
@@ -22,92 +19,4 @@ internal static class ThrowHelper
{
throw new ArgumentException(message, paramName);
}
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static DatabaseCorruptedException DatabaseCorrupted(string message, Exception? inner)
- {
- throw new DatabaseCorruptedException(message, inner);
- }
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static GameFileOperationException GameFileOperation(string message, Exception? inner)
- {
- throw new GameFileOperationException(message, inner);
- }
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static InvalidDataException InvalidData(string message, Exception? inner = default)
- {
- throw new InvalidDataException(message, inner);
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static void InvalidDataIf([DoesNotReturnIf(true)] bool condition, string message, Exception? inner = default)
- {
- if (condition)
- {
- throw new InvalidDataException(message, inner);
- }
- }
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static InvalidOperationException InvalidOperation(string message, Exception? inner = default)
- {
- throw new InvalidOperationException(message, inner);
- }
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static NotSupportedException NotSupported()
- {
- throw new NotSupportedException();
- }
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static NotSupportedException NotSupported(string message)
- {
- throw new NotSupportedException(message);
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static void NotSupportedIf(bool condition, string message)
- {
- if (condition)
- {
- throw new NotSupportedException(message);
- }
- }
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static OperationCanceledException OperationCanceled(string message, Exception? inner = default)
- {
- throw new OperationCanceledException(message, inner);
- }
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static PackageConvertException PackageConvert(string message, Exception? inner = default)
- {
- throw new PackageConvertException(message, inner);
- }
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static RuntimeEnvironmentException RuntimeEnvironment(string message, Exception? inner)
- {
- throw new RuntimeEnvironmentException(message, inner);
- }
-
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static UserdataCorruptedException UserdataCorrupted(string message, Exception? inner)
- {
- throw new UserdataCorruptedException(message, inner);
- }
}
\ No newline at end of file
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/UserdataCorruptedException.cs b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/UserdataCorruptedException.cs
deleted file mode 100644
index d8de5ec5..00000000
--- a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/UserdataCorruptedException.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (c) DGP Studio. All rights reserved.
-// Licensed under the MIT license.
-
-namespace Snap.Hutao.Core.ExceptionService;
-
-///
-/// 用户数据损坏异常
-///
-[HighQuality]
-[Obsolete("Use HutaoException instead")]
-internal sealed class UserdataCorruptedException : Exception
-{
- ///
- /// 构造一个新的用户数据损坏异常
- ///
- /// 消息
- /// 内部错误
- public UserdataCorruptedException(string message, Exception? innerException)
- : base(SH.FormatCoreExceptionServiceUserdataCorruptedMessage($"{message}\n{innerException?.Message}"), innerException)
- {
- }
-}
\ No newline at end of file
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/IO/Http/Sharding/HttpShardCopyWorker.cs b/src/Snap.Hutao/Snap.Hutao/Core/IO/Http/Sharding/HttpShardCopyWorker.cs
index 3c345662..12bcd97b 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/IO/Http/Sharding/HttpShardCopyWorker.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/IO/Http/Sharding/HttpShardCopyWorker.cs
@@ -78,7 +78,7 @@ internal sealed class HttpShardCopyWorker : IDisposable
using (HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
- using (IMemoryOwner memoryOwner = MemoryPool.Shared.Rent())
+ using (IMemoryOwner memoryOwner = MemoryPool.Shared.Rent(bufferSize))
{
Memory buffer = memoryOwner.Memory;
using (Stream stream = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false))
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/IO/StreamReaderWriter.cs b/src/Snap.Hutao/Snap.Hutao/Core/IO/StreamReaderWriter.cs
index 70690a23..5dedbec3 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/IO/StreamReaderWriter.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/IO/StreamReaderWriter.cs
@@ -27,6 +27,7 @@ internal sealed class StreamReaderWriter : IDisposable
}
///
+ [SuppressMessage("", "SH003")]
public Task WriteAsync(string value)
{
return writer.WriteAsync(value);
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Json/Converter/SeparatorCommaInt32EnumerableConverter.cs b/src/Snap.Hutao/Snap.Hutao/Core/Json/Converter/SeparatorCommaInt32EnumerableConverter.cs
index 669e2e32..49e1773d 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/Json/Converter/SeparatorCommaInt32EnumerableConverter.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/Json/Converter/SeparatorCommaInt32EnumerableConverter.cs
@@ -22,7 +22,7 @@ internal sealed class SeparatorCommaInt32EnumerableConverter : JsonConverter();
+ return [];
}
///
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Logging/LoggerExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/Logging/LoggerExtension.cs
index 747a3471..c7685cd9 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/Logging/LoggerExtension.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/Logging/LoggerExtension.cs
@@ -83,9 +83,10 @@ internal static class LoggerExtension
logger.LogColorized(logLevel, 0, exception, message, args);
}
+ [SuppressMessage("", "CA2254")]
public static void LogColorized(this ILogger logger, LogLevel logLevel, EventId eventId, Exception? exception, LogMessage message, params LogArgument[] args)
{
- string colorizedMessage = Colorize(message, args, out object?[] outArgs)!;
+ string? colorizedMessage = Colorize(message, args, out object?[] outArgs);
logger.Log(logLevel, eventId, exception, colorizedMessage, outArgs);
}
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Validation/Must.cs b/src/Snap.Hutao/Snap.Hutao/Core/Validation/Must.cs
deleted file mode 100644
index 712f1c81..00000000
--- a/src/Snap.Hutao/Snap.Hutao/Core/Validation/Must.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) DGP Studio. All rights reserved.
-// Licensed under the MIT license.
-
-using System.Runtime.CompilerServices;
-
-namespace Snap.Hutao.Core.Validation;
-
-///
-/// 封装验证方法,简化微软验证
-///
-[HighQuality]
-[Obsolete("Use HutaoException instead")]
-internal static class Must
-{
- ///
- /// Throws an if a condition does not evaluate to true.
- ///
- /// The condition to check.
- /// message
- /// The name of the parameter to blame in the exception, if thrown.
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static void Argument([DoesNotReturnIf(false)] bool condition, string? message, [CallerArgumentExpression(nameof(condition))] string? parameterName = null)
- {
- if (!condition)
- {
- throw new ArgumentException(message, parameterName);
- }
- }
-
- ///
- /// Throws an if a condition does not evaluate to true.
- ///
- /// The condition to check.
- /// message
- /// The name of the parameter to blame in the exception, if thrown.
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static void Range([DoesNotReturnIf(false)] bool condition, string? message, [CallerArgumentExpression(nameof(condition))] string? parameterName = null)
- {
- if (!condition)
- {
- throw new ArgumentOutOfRangeException(parameterName, message);
- }
- }
-
- ///
- /// Unconditionally throws an .
- ///
- /// 上下文
- /// Nothing. This method always throws.
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static Exception NeverHappen(string? context = null)
- {
- throw new NotSupportedException(context);
- }
-}
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyCombination.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyCombination.cs
index 481135ca..edd0c9bd 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyCombination.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyCombination.cs
@@ -34,6 +34,7 @@ internal sealed class HotKeyCombination : ObservableObject
private VirtualKey key;
private bool isEnabled;
+ [SuppressMessage("", "SH002")]
public HotKeyCombination(IServiceProvider serviceProvider, HWND hwnd, string settingKey, int hotKeyId, HOT_KEY_MODIFIERS defaultModifiers, VirtualKey defaultKey)
{
infoBarService = serviceProvider.GetRequiredService();
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs
index 41619dc0..b8570522 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconController.cs
@@ -31,6 +31,7 @@ internal sealed class NotifyIconController : IDisposable
id = Unsafe.As(ref MemoryMarshal.GetArrayDataReference(MD5.HashData(Encoding.UTF8.GetBytes(iconFile.Path))));
xamlHostWindow = new(serviceProvider);
+ xamlHostWindow.MoveAndResize(default);
messageWindow = new()
{
@@ -39,7 +40,6 @@ internal sealed class NotifyIconController : IDisposable
};
CreateNotifyIcon();
- xamlHostWindow.MoveAndResize(GetRect());
}
public void Dispose()
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs
index 39b6edf0..2269eaf0 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs
@@ -143,6 +143,7 @@ internal sealed class NotifyIconMessageWindow : IDisposable
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
+ [UnconditionalSuppressMessage("", "CS0649")]
private readonly struct LPARAM2
{
public readonly uint Low;
diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowNonRudeHWND.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowNonRudeHWND.cs
index 6c993d32..8bc003b8 100644
--- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowNonRudeHWND.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowNonRudeHWND.cs
@@ -12,6 +12,7 @@ internal sealed class XamlWindowNonRudeHWND : IDisposable
private const string NonRudeHWND = "NonRudeHWND";
private readonly HWND hwnd;
+ [SuppressMessage("", "SH002")]
public XamlWindowNonRudeHWND(HWND hwnd)
{
this.hwnd = hwnd;
diff --git a/src/Snap.Hutao/Snap.Hutao/GlobalUsing.cs b/src/Snap.Hutao/Snap.Hutao/GlobalUsing.cs
index 5ba3272f..f49632c2 100644
--- a/src/Snap.Hutao/Snap.Hutao/GlobalUsing.cs
+++ b/src/Snap.Hutao/Snap.Hutao/GlobalUsing.cs
@@ -14,7 +14,6 @@ global using Snap.Hutao.Core.Annotation;
global using Snap.Hutao.Core.DependencyInjection;
global using Snap.Hutao.Core.DependencyInjection.Annotation;
global using Snap.Hutao.Core.Threading;
-global using Snap.Hutao.Core.Validation;
global using Snap.Hutao.Extension;
global using Snap.Hutao.Resource.Localization;
diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/Frozen/IntrinsicFrozen.cs b/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/Frozen/IntrinsicFrozen.cs
index 7d9604a8..b214f0f7 100644
--- a/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/Frozen/IntrinsicFrozen.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/Frozen/IntrinsicFrozen.cs
@@ -11,25 +11,25 @@ namespace Snap.Hutao.Model.Intrinsic.Frozen;
[HighQuality]
internal static class IntrinsicFrozen
{
- public static FrozenSet AssociationTypes { get; } = Enum.GetValues().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType().ToFrozenSet();
+ public static FrozenSet AssociationTypes { get; } = NamesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
- public static FrozenSet> AssociationTypeNameValues { get; } = Enum.GetValues().Select(e => new NameValue(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
+ public static FrozenSet> AssociationTypeNameValues { get; } = NameValuesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
- public static FrozenSet WeaponTypes { get; } = Enum.GetValues().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType().ToFrozenSet();
+ public static FrozenSet WeaponTypes { get; } = NamesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
- public static FrozenSet> WeaponTypeNameValues { get; } = Enum.GetValues().Select(e => new NameValue(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
+ public static FrozenSet> WeaponTypeNameValues { get; } = NameValuesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
- public static FrozenSet ItemQualities { get; } = Enum.GetValues().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType().ToFrozenSet();
+ public static FrozenSet ItemQualities { get; } = NamesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
- public static FrozenSet> ItemQualityNameValues { get; } = Enum.GetValues().Select(e => new NameValue(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
+ public static FrozenSet> ItemQualityNameValues { get; } = NameValuesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
- public static FrozenSet BodyTypes { get; } = Enum.GetValues().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType().ToFrozenSet();
+ public static FrozenSet BodyTypes { get; } = NamesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
- public static FrozenSet> BodyTypeNameValues { get; } = Enum.GetValues().Select(e => new NameValue(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
+ public static FrozenSet> BodyTypeNameValues { get; } = NameValuesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
- public static FrozenSet FightProperties { get; } = Enum.GetValues().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType().ToFrozenSet();
+ public static FrozenSet FightProperties { get; } = NamesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
- public static FrozenSet> FightPropertyNameValues { get; } = Enum.GetValues().Select(e => new NameValue(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
+ public static FrozenSet> FightPropertyNameValues { get; } = NameValuesFromEnum(e => e.GetLocalizedDescriptionOrDefault());
public static FrozenSet ElementNames { get; } = FrozenSet.ToFrozenSet(
[
@@ -63,4 +63,50 @@ internal static class IntrinsicFrozen
SH.ModelMetadataMaterialWeaponEnhancementMaterial,
SH.ModelMetadataMaterialWeaponAscensionMaterial,
]);
+
+ private static FrozenSet NamesFromEnum(Func selector)
+ where TEnum : struct, Enum
+ {
+ return NamesFromEnumValues(Enum.GetValues(), selector);
+ }
+
+ private static FrozenSet NamesFromEnumValues(TEnum[] values, Func selector)
+ {
+ return NotNull(values, selector).ToFrozenSet();
+
+ static IEnumerable NotNull(TEnum[] values, Func selector)
+ {
+ foreach (TEnum value in values)
+ {
+ string? name = selector(value);
+ if (!string.IsNullOrEmpty(name))
+ {
+ yield return name;
+ }
+ }
+ }
+ }
+
+ private static FrozenSet> NameValuesFromEnum(Func selector)
+ where TEnum : struct, Enum
+ {
+ return NameValuesFromEnumValues(Enum.GetValues(), selector);
+ }
+
+ private static FrozenSet> NameValuesFromEnumValues(TEnum[] values, Func selector)
+ {
+ return NotNull(values, selector).ToFrozenSet();
+
+ static IEnumerable> NotNull(TEnum[] values, Func selector)
+ {
+ foreach (TEnum value in values)
+ {
+ string? name = selector(value);
+ if (!string.IsNullOrEmpty(name))
+ {
+ yield return new(name, value);
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/AvatarInfoDbBulkOperation.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/AvatarInfoDbBulkOperation.cs
index 222047b3..4e6bca1c 100644
--- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/AvatarInfoDbBulkOperation.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/AvatarInfoDbBulkOperation.cs
@@ -32,7 +32,7 @@ internal sealed partial class AvatarInfoDbBulkOperation
public async ValueTask> UpdateDbAvatarInfosByShowcaseAsync(string uid, IEnumerable webInfos, CancellationToken token)
{
- List dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
+ List dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
EnsureItemsAvatarIdUnique(ref dbInfos, uid, out Dictionary dbInfoMap);
using (IServiceScope scope = serviceProvider.CreateScope())
@@ -50,14 +50,14 @@ internal sealed partial class AvatarInfoDbBulkOperation
AddOrUpdateAvatarInfo(entity, uid, appDbContext, webInfo);
}
- return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
+ return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
}
}
public async ValueTask> UpdateDbAvatarInfosByGameRecordCharacterAsync(UserAndUid userAndUid, CancellationToken token)
{
string uid = userAndUid.Uid.Value;
- List dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
+ List dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
EnsureItemsAvatarIdUnique(ref dbInfos, uid, out Dictionary dbInfoMap);
using (IServiceScope scope = serviceProvider.CreateScope())
@@ -103,14 +103,14 @@ internal sealed partial class AvatarInfoDbBulkOperation
}
Return:
- return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
+ return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
}
public async ValueTask> UpdateDbAvatarInfosByCalculateAvatarDetailAsync(UserAndUid userAndUid, CancellationToken token)
{
token.ThrowIfCancellationRequested();
string uid = userAndUid.Uid.Value;
- List dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
+ List dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
EnsureItemsAvatarIdUnique(ref dbInfos, uid, out Dictionary dbInfoMap);
using (IServiceScope scope = serviceProvider.CreateScope())
@@ -146,7 +146,7 @@ internal sealed partial class AvatarInfoDbBulkOperation
}
}
- return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
+ return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/Builder/AvatarViewBuilderExtension.cs b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/Builder/AvatarViewBuilderExtension.cs
index 12b2164a..e139a9ab 100644
--- a/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/Builder/AvatarViewBuilderExtension.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Service/AvatarInfo/Factory/Builder/AvatarViewBuilderExtension.cs
@@ -32,6 +32,7 @@ internal static class AvatarViewBuilderExtension
return builder;
}
+ [SuppressMessage("", "SH002")]
public static TBuilder SetCalculatorRefreshTimeFormat(this TBuilder builder, DateTimeOffset refreshTime, Func