From af583c101c7732cd5132a81d2cd571e6693f2ca2 Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Sun, 1 Feb 2026 14:07:48 +0800
Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E9=87=8D=E6=9E=84=E5=8D=8F?=
=?UTF-8?q?=E7=A8=8B=E6=89=A9=E5=B1=95=E5=92=8C=E5=87=BD=E6=95=B0=E5=BC=8F?=
=?UTF-8?q?=E7=BC=96=E7=A8=8B=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 优化 CommandCoroutineExtensions 中的代码格式和异常处理逻辑
- 简化 WaitForEvent 和 WaitForEventWithTimeout 中的EventData属性实现
- 调整 EventListenerScope 中的EventData属性访问器
- 重构 ControlExtensions 中 TakeIf 和 TakeUnless 方法的实现
- 优化 FunctionExtensions 中 Repeat 和 Partial 方法的代码结构
- 调整 PipeExtensions 和其他扩展类的文档注释格式
- 修改测试代码中的协程迭代和事件注册相关实现
- 优化 DataRepository 中的异步操作实现方式
= [release ci]
---
.../data/ILoadableFrom.cs | 4 +-
.../CommandCoroutineExtensionsTests.cs | 54 ++++--------
.../CoroutineComposeExtensionsTests.cs | 35 ++------
.../coroutine/CoroutineHelperTests.cs | 2 +-
.../QueryCoroutineExtensionsTests.cs | 82 +++++++++++++------
.../events/EventListenerScopeTests.cs | 8 +-
.../control/ControlExtensionsTests.cs | 18 ++--
.../functions/FunctionExtensionsTests.cs | 8 +-
.../functional/pipe/PipeExtensionsTests.cs | 6 +-
.../extensions/CommandCoroutineExtensions.cs | 20 ++---
.../extensions/CoroutineComposeExtensions.cs | 6 +-
.../extensions/QueryCoroutineExtensions.cs | 6 +-
.../coroutine/instructions/WaitForEvent.cs | 5 +-
.../instructions/WaitForEventWithTimeout.cs | 15 ++--
GFramework.Core/events/EventListenerScope.cs | 17 ++--
.../functional/control/ControlExtensions.cs | 14 ++--
.../functions/FunctionExtensions.cs | 35 ++++----
.../functional/pipe/PipeExtensions.cs | 9 +-
.../data/IDataLocation.cs | 12 +--
.../data/IDataLocationProvider.cs | 8 +-
.../data/IDataRepository.cs | 10 +--
.../data/ISettingsDataRepository.cs | 10 +--
.../data/IVersionedData.cs | 13 +--
.../data/events/DataDeletedEvent.cs | 3 +-
.../enums/{StorageKind.cs => StorageKinds.cs} | 28 +++----
.../setting/IResetApplyAbleSettings.cs | 8 +-
.../setting/ISettingsData.cs | 4 +-
.../setting/ISettingsModel.cs | 28 +++----
.../setting/data/AudioSettings.cs | 5 +-
.../setting/data/GraphicsSettings.cs | 5 +-
.../setting/data/LocalizationSettings.cs | 5 +-
GFramework.Game/data/DataRepository.cs | 31 ++++---
.../data/UnifiedSettingsDataRepository.cs | 4 -
GFramework.Game/data/UnifiedSettingsFile.cs | 16 ++--
.../extensions/DataLocationExtensions.cs | 6 +-
GFramework.Game/setting/SettingsModel.cs | 8 +-
GFramework.Game/storage/FileStorage.cs | 3 +-
37 files changed, 257 insertions(+), 294 deletions(-)
rename GFramework.Game.Abstractions/enums/{StorageKind.cs => StorageKinds.cs} (73%)
diff --git a/GFramework.Core.Abstractions/data/ILoadableFrom.cs b/GFramework.Core.Abstractions/data/ILoadableFrom.cs
index 9b696a5..bb773f7 100644
--- a/GFramework.Core.Abstractions/data/ILoadableFrom.cs
+++ b/GFramework.Core.Abstractions/data/ILoadableFrom.cs
@@ -14,13 +14,13 @@
namespace GFramework.Core.Abstractions.data;
///
-/// 定义从指定类型数据源加载数据的接口
+/// 定义从指定类型数据源加载数据的接口
///
/// 数据源的类型
public interface ILoadableFrom
{
///
- /// 从指定的数据源加载数据到当前对象
+ /// 从指定的数据源加载数据到当前对象
///
/// 用作数据源的对象,类型为T
void LoadFrom(T source);
diff --git a/GFramework.Core.Tests/coroutine/CommandCoroutineExtensionsTests.cs b/GFramework.Core.Tests/coroutine/CommandCoroutineExtensionsTests.cs
index 408b83a..29aadb1 100644
--- a/GFramework.Core.Tests/coroutine/CommandCoroutineExtensionsTests.cs
+++ b/GFramework.Core.Tests/coroutine/CommandCoroutineExtensionsTests.cs
@@ -25,8 +25,16 @@ public class CommandCoroutineExtensionsTests
private class TestCommand : IAsyncCommand
{
private IArchitectureContext? _context;
- public void SetContext(IArchitectureContext context) => _context = context;
- public IArchitectureContext GetContext() => _context!;
+
+ public void SetContext(IArchitectureContext context)
+ {
+ _context = context;
+ }
+
+ public IArchitectureContext GetContext()
+ {
+ return _context!;
+ }
public Task ExecuteAsync()
{
@@ -47,7 +55,7 @@ public class CommandCoroutineExtensionsTests
///
private class TestContextAware : IContextAware
{
- public Mock _mockContext = new();
+ public readonly Mock _mockContext = new();
public IArchitectureContext GetContext()
{
@@ -78,13 +86,9 @@ public class CommandCoroutineExtensionsTests
// 迭代协程直到完成
while (coroutine.MoveNext())
- {
if (coroutine.Current is WaitForTask)
- {
// 等待任务完成
await Task.Delay(10);
- }
- }
Assert.That(capturedException, Is.Null);
}
@@ -109,13 +113,9 @@ public class CommandCoroutineExtensionsTests
// 迭代协程直到完成
while (coroutine.MoveNext())
- {
if (coroutine.Current is WaitForTask)
- {
// 等待任务完成
await Task.Delay(10);
- }
- }
Assert.That(capturedException, Is.Not.Null);
// 异常被包装为 AggregateException
@@ -140,17 +140,13 @@ public class CommandCoroutineExtensionsTests
.Returns(Task.FromException(expectedException));
// 使用null作为错误处理程序
- var coroutine = contextAware.SendCommandCoroutineWithErrorHandler(command, null);
+ var coroutine = contextAware.SendCommandCoroutineWithErrorHandler(command);
// 迭代协程直到完成
while (coroutine.MoveNext())
- {
if (coroutine.Current is WaitForTask)
- {
// 等待任务完成
await Task.Delay(10);
- }
- }
// 应该不会抛出异常
Assert.Pass();
@@ -172,7 +168,7 @@ public class CommandCoroutineExtensionsTests
var unRegisterMock = new Mock();
Action? eventCallback = null;
- eventBusMock.Setup(bus => bus.Register(It.IsAny>()))
+ eventBusMock.Setup(bus => bus.Register(It.IsAny>()))
.Returns(unRegisterMock.Object)
.Callback>(callback => eventCallback = callback);
@@ -196,10 +192,7 @@ public class CommandCoroutineExtensionsTests
// 启动协程并等待命令执行完成
coroutine.MoveNext(); // 进入命令发送阶段
- if (coroutine.Current is WaitForTask)
- {
- await Task.Delay(10); // 等待命令任务完成
- }
+ if (coroutine.Current is WaitForTask) await Task.Delay(10); // 等待命令任务完成
// 此时协程应该在等待事件
Assert.That(coroutine.MoveNext(), Is.True); // 等待事件阶段
@@ -252,13 +245,9 @@ public class CommandCoroutineExtensionsTests
// 运行协程直到完成
while (coroutine.MoveNext())
- {
if (coroutine.Current is WaitForEventWithTimeout timeoutWait)
- {
// 模拟超时
timeoutWait.Update(0.2); // 更新时间超过超时限制
- }
- }
});
}
@@ -292,15 +281,11 @@ public class CommandCoroutineExtensionsTests
// 使用null作为事件回调
var coroutine = contextAware.SendCommandAndWaitEventCoroutine(
- command,
- null); // null回调
+ command); // null回调
// 启动协程
coroutine.MoveNext(); // 进入命令发送阶段
- if (coroutine.Current is WaitForTask)
- {
- await Task.Delay(10); // 等待命令任务完成
- }
+ if (coroutine.Current is WaitForTask) await Task.Delay(10); // 等待命令任务完成
// 触发事件
var testEvent = new TestEvent { Data = "TestData" };
@@ -343,10 +328,7 @@ public class CommandCoroutineExtensionsTests
// 启动协程 - 命令失败时协程仍然继续
coroutine.MoveNext(); // 进入命令发送阶段
- if (coroutine.Current is WaitForTask)
- {
- await Task.Delay(10); // 等待命令任务完成
- }
+ if (coroutine.Current is WaitForTask) await Task.Delay(10); // 等待命令任务完成
// 命令执行失败后,协程继续执行
Assert.Pass();
@@ -384,7 +366,7 @@ public class CommandCoroutineExtensionsTests
var eventBusMock = new Mock();
var unRegisterMock = new Mock();
- eventBusMock.Setup(bus => bus.Register(It.IsAny>()))
+ eventBusMock.Setup(bus => bus.Register(It.IsAny>()))
.Returns(unRegisterMock.Object);
// 设置上下文服务以返回事件总线
diff --git a/GFramework.Core.Tests/coroutine/CoroutineComposeExtensionsTests.cs b/GFramework.Core.Tests/coroutine/CoroutineComposeExtensionsTests.cs
index 52dba5b..bb8d9d1 100644
--- a/GFramework.Core.Tests/coroutine/CoroutineComposeExtensionsTests.cs
+++ b/GFramework.Core.Tests/coroutine/CoroutineComposeExtensionsTests.cs
@@ -50,10 +50,7 @@ public class CoroutineComposeExtensionsTests
var combined = first.Then(() => executionOrder.Add("action"));
// 执行组合协程
- while (combined.MoveNext())
- {
- combined.Current.Update(0.016);
- }
+ while (combined.MoveNext()) combined.Current.Update(0.016);
Assert.That(executionOrder.Count, Is.EqualTo(3));
Assert.That(executionOrder[0], Is.EqualTo("coroutine"));
@@ -112,10 +109,7 @@ public class CoroutineComposeExtensionsTests
.Then(() => executionOrder.Add(2))
.Then(() => executionOrder.Add(3));
- while (combined.MoveNext())
- {
- combined.Current.Update(0.016);
- }
+ while (combined.MoveNext()) combined.Current.Update(0.016);
Assert.That(executionOrder, Is.EqualTo([1, 2, 3]));
}
@@ -162,10 +156,7 @@ public class CoroutineComposeExtensionsTests
var second = CreateTestCoroutine(2, () => executionOrder.Add("second"));
var combined = first.Then(second);
- while (combined.MoveNext())
- {
- combined.Current.Update(0.016);
- }
+ while (combined.MoveNext()) combined.Current.Update(0.016);
Assert.That(executionOrder.Count, Is.EqualTo(4));
Assert.That(executionOrder[0], Is.EqualTo("first"));
@@ -206,10 +197,7 @@ public class CoroutineComposeExtensionsTests
var second = CreateTestCoroutine(0);
var combined = first.Then(second);
- while (combined.MoveNext())
- {
- combined.Current.Update(0.016);
- }
+ while (combined.MoveNext()) combined.Current.Update(0.016);
Assert.That(firstExecuteCount, Is.EqualTo(2));
}
@@ -262,10 +250,7 @@ public class CoroutineComposeExtensionsTests
var combined = first.Then(second).Then(third);
- while (combined.MoveNext())
- {
- combined.Current.Update(0.016);
- }
+ while (combined.MoveNext()) combined.Current.Update(0.016);
Assert.That(executionOrder, Is.EqualTo(new[] { 1, 2, 3 }));
}
@@ -286,10 +271,7 @@ public class CoroutineComposeExtensionsTests
.Then(second)
.Then(() => executionOrder.Add("action2"));
- while (combined.MoveNext())
- {
- combined.Current.Update(0.016);
- }
+ while (combined.MoveNext()) combined.Current.Update(0.016);
Assert.That(executionOrder, Is.EqualTo(new[] { "coroutine1", "action1", "coroutine2", "action2" }));
}
@@ -339,10 +321,7 @@ public class CoroutineComposeExtensionsTests
coroutine = coroutine.Then(nextCoroutine);
}
- while (coroutine.MoveNext())
- {
- coroutine.Current.Update(0.016);
- }
+ while (coroutine.MoveNext()) coroutine.Current.Update(0.016);
Assert.That(count, Is.EqualTo(11));
}
diff --git a/GFramework.Core.Tests/coroutine/CoroutineHelperTests.cs b/GFramework.Core.Tests/coroutine/CoroutineHelperTests.cs
index 7efbfb0..636aabd 100644
--- a/GFramework.Core.Tests/coroutine/CoroutineHelperTests.cs
+++ b/GFramework.Core.Tests/coroutine/CoroutineHelperTests.cs
@@ -443,7 +443,7 @@ public class CoroutineHelperTests
public void RepeatCallForever_Should_Execute_Forever_When_ShouldContinue_Is_Null()
{
var callCount = 0;
- var coroutine = CoroutineHelper.RepeatCallForever(0.1, () => callCount++, (Func?)null);
+ var coroutine = CoroutineHelper.RepeatCallForever(0.1, () => callCount++);
for (var i = 0; i < 5; i++)
{
diff --git a/GFramework.Core.Tests/coroutine/QueryCoroutineExtensionsTests.cs b/GFramework.Core.Tests/coroutine/QueryCoroutineExtensionsTests.cs
index 422d175..9a720cf 100644
--- a/GFramework.Core.Tests/coroutine/QueryCoroutineExtensionsTests.cs
+++ b/GFramework.Core.Tests/coroutine/QueryCoroutineExtensionsTests.cs
@@ -23,9 +23,21 @@ public class QueryCoroutineExtensionsTests
{
private IArchitectureContext? _context;
public string QueryData { get; set; } = string.Empty;
- public void SetContext(IArchitectureContext context) => _context = context;
- public IArchitectureContext GetContext() => _context!;
- public string Do() => QueryData;
+
+ public void SetContext(IArchitectureContext context)
+ {
+ _context = context;
+ }
+
+ public IArchitectureContext GetContext()
+ {
+ return _context!;
+ }
+
+ public string Do()
+ {
+ return QueryData;
+ }
}
///
@@ -33,7 +45,7 @@ public class QueryCoroutineExtensionsTests
///
private class TestContextAware : IContextAware
{
- public Mock _mockContext = new Mock();
+ public readonly Mock _mockContext = new();
public IArchitectureContext GetContext()
{
@@ -58,7 +70,7 @@ public class QueryCoroutineExtensionsTests
// 设置上下文发送查询的模拟行为
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Returns("TestResult");
var coroutine = contextAware.SendQueryCoroutine(query, result =>
@@ -90,7 +102,7 @@ public class QueryCoroutineExtensionsTests
// 设置上下文发送查询的模拟行为
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Returns(true);
var coroutine = contextAware.SendQueryCoroutine(query, result =>
@@ -118,7 +130,7 @@ public class QueryCoroutineExtensionsTests
// 设置上下文发送查询的模拟行为
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Returns("TestResult");
// 使用null作为结果回调,应该抛出NullReferenceException
@@ -141,7 +153,7 @@ public class QueryCoroutineExtensionsTests
// 设置上下文发送查询的模拟行为
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Returns("ProcessedResult");
var coroutine = contextAware.SendQueryCoroutine(query, result =>
@@ -168,7 +180,7 @@ public class QueryCoroutineExtensionsTests
// 设置上下文发送查询的模拟行为
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Returns("TestResult");
var coroutine = contextAware.SendQueryCoroutine(query, result => { });
@@ -189,7 +201,7 @@ public class QueryCoroutineExtensionsTests
// 设置上下文发送查询的模拟行为,让它抛出异常
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Throws(expectedException);
// 由于SendQueryCoroutine会直接执行查询,这可能导致异常
@@ -216,7 +228,7 @@ public class QueryCoroutineExtensionsTests
// 设置上下文发送查询的模拟行为,并捕获传入的查询参数
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Returns((IQuery q) =>
{
capturedQuery = (TestQuery)q;
@@ -258,7 +270,7 @@ public class QueryCoroutineExtensionsTests
// 设置上下文发送查询的模拟行为
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Returns(expectedResult);
var coroutine =
@@ -284,7 +296,7 @@ public class QueryCoroutineExtensionsTests
// 设置上下文发送查询的模拟行为,返回空字符串
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Returns(string.Empty);
var coroutine =
@@ -302,12 +314,12 @@ public class QueryCoroutineExtensionsTests
public void SendQueryCoroutine_Should_Handle_Null_Result()
{
var query = new TestQuery { QueryData = "TestQueryData" };
- string? receivedResult = "initial";
+ var receivedResult = "initial";
var contextAware = new TestContextAware();
// 设置上下文发送查询的模拟行为,返回null
contextAware._mockContext
- .Setup(ctx => ctx.SendQuery(It.IsAny()))
+ .Setup(ctx => ctx.SendQuery(It.IsAny()))
.Returns((string)null!);
var coroutine =
@@ -326,9 +338,21 @@ internal class IntQuery : IQuery
{
private IArchitectureContext? _context;
public int Value { get; set; }
- public void SetContext(IArchitectureContext context) => _context = context;
- public IArchitectureContext GetContext() => _context!;
- public bool Do() => Value > 0;
+
+ public void SetContext(IArchitectureContext context)
+ {
+ _context = context;
+ }
+
+ public IArchitectureContext GetContext()
+ {
+ return _context!;
+ }
+
+ public bool Do()
+ {
+ return Value > 0;
+ }
}
///
@@ -338,11 +362,23 @@ internal class ComplexQuery : IQuery
{
private IArchitectureContext? _context;
public string Name { get; set; } = string.Empty;
- public List Values { get; set; } = new List();
- public Dictionary Metadata { get; set; } = new Dictionary();
- public void SetContext(IArchitectureContext context) => _context = context;
- public IArchitectureContext GetContext() => _context!;
- public ComplexResult Do() => new ComplexResult { ProcessedName = Name, Sum = Values.Sum(), Count = Values.Count };
+ public List Values { get; set; } = new();
+ public Dictionary Metadata { get; set; } = new();
+
+ public void SetContext(IArchitectureContext context)
+ {
+ _context = context;
+ }
+
+ public IArchitectureContext GetContext()
+ {
+ return _context!;
+ }
+
+ public ComplexResult Do()
+ {
+ return new ComplexResult { ProcessedName = Name, Sum = Values.Sum(), Count = Values.Count };
+ }
}
///
diff --git a/GFramework.Core.Tests/events/EventListenerScopeTests.cs b/GFramework.Core.Tests/events/EventListenerScopeTests.cs
index b63e28f..590bf06 100644
--- a/GFramework.Core.Tests/events/EventListenerScopeTests.cs
+++ b/GFramework.Core.Tests/events/EventListenerScopeTests.cs
@@ -217,7 +217,7 @@ public class EventListenerScopeTests
var eventBusMock = new Mock();
var unRegisterMock = new Mock();
- eventBusMock.Setup(x => x.Register(It.IsAny>()))
+ eventBusMock.Setup(x => x.Register(It.IsAny>()))
.Returns(unRegisterMock.Object)
.Callback>(action => registeredAction = action);
@@ -242,7 +242,7 @@ public class EventListenerScopeTests
var eventBusMock = new Mock();
var unRegisterMock = new Mock();
- eventBusMock.Setup(x => x.Register(It.IsAny>()))
+ eventBusMock.Setup(x => x.Register(It.IsAny>()))
.Returns(unRegisterMock.Object)
.Callback>(action => registeredAction = action);
@@ -268,7 +268,7 @@ public class EventListenerScopeTests
var eventBusMock = new Mock();
var unRegisterMock = new Mock();
- eventBusMock.Setup(x => x.Register(It.IsAny>()))
+ eventBusMock.Setup(x => x.Register(It.IsAny>()))
.Returns(unRegisterMock.Object)
.Callback>(action => registeredAction = action);
@@ -290,7 +290,7 @@ public class EventListenerScopeTests
{
var eventBusMock = new Mock();
var unRegisterMock = new Mock();
- eventBusMock.Setup(x => x.Register(It.IsAny>()))
+ eventBusMock.Setup(x => x.Register(It.IsAny>()))
.Returns(unRegisterMock.Object);
var scope = new EventListenerScope(eventBusMock.Object);
diff --git a/GFramework.Core.Tests/functional/control/ControlExtensionsTests.cs b/GFramework.Core.Tests/functional/control/ControlExtensionsTests.cs
index 46d81e0..e646cb1 100644
--- a/GFramework.Core.Tests/functional/control/ControlExtensionsTests.cs
+++ b/GFramework.Core.Tests/functional/control/ControlExtensionsTests.cs
@@ -4,19 +4,19 @@ using NUnit.Framework;
namespace GFramework.Core.Tests.functional.control;
///
-/// ControlExtensions扩展方法测试类,用于验证控制流函数式编程扩展方法的正确性
+/// ControlExtensions扩展方法测试类,用于验证控制流函数式编程扩展方法的正确性
///
[TestFixture]
public class ControlExtensionsTests
{
///
- /// 测试TakeIf方法 - 验证条件为真时返回原值
+ /// 测试TakeIf方法 - 验证条件为真时返回原值
///
[Test]
public void TakeIf_Should_Return_Value_When_Condition_Is_True()
{
// Arrange
- string str = "Hello";
+ var str = "Hello";
// Act
var result = str.TakeIf(s => s.Length > 3);
@@ -26,13 +26,13 @@ public class ControlExtensionsTests
}
///
- /// 测试TakeIf方法 - 验证条件为假时返回null
+ /// 测试TakeIf方法 - 验证条件为假时返回null
///
[Test]
public void TakeIf_Should_Return_Null_When_Condition_Is_False()
{
// Arrange
- string str = "Hi";
+ var str = "Hi";
// Act
var result = str.TakeIf(s => s.Length > 3);
@@ -42,13 +42,13 @@ public class ControlExtensionsTests
}
///
- /// 测试TakeUnless方法 - 验证条件为假时返回原值
+ /// 测试TakeUnless方法 - 验证条件为假时返回原值
///
[Test]
public void TakeUnless_Should_Return_Value_When_Condition_Is_False()
{
// Arrange
- string str = "Hi";
+ var str = "Hi";
// Act
var result = str.TakeUnless(s => s.Length > 3);
@@ -58,13 +58,13 @@ public class ControlExtensionsTests
}
///
- /// 测试TakeUnless方法 - 验证条件为真时返回null
+ /// 测试TakeUnless方法 - 验证条件为真时返回null
///
[Test]
public void TakeUnless_Should_Return_Null_When_Condition_Is_True()
{
// Arrange
- string str = "Hello";
+ var str = "Hello";
// Act
var result = str.TakeUnless(s => s.Length > 3);
diff --git a/GFramework.Core.Tests/functional/functions/FunctionExtensionsTests.cs b/GFramework.Core.Tests/functional/functions/FunctionExtensionsTests.cs
index 5544159..0523f59 100644
--- a/GFramework.Core.Tests/functional/functions/FunctionExtensionsTests.cs
+++ b/GFramework.Core.Tests/functional/functions/FunctionExtensionsTests.cs
@@ -4,14 +4,14 @@ using NUnit.Framework;
namespace GFramework.Core.Tests.functional.functions;
///
-/// FunctionExtensions扩展方法测试类,用于验证高级函数式编程扩展方法的正确性
-/// 包括柯里化、偏函数应用、重复执行、安全执行和缓存等功能的测试
+/// FunctionExtensions扩展方法测试类,用于验证高级函数式编程扩展方法的正确性
+/// 包括柯里化、偏函数应用、重复执行、安全执行和缓存等功能的测试
///
[TestFixture]
public class FunctionExtensionsTests
{
///
- /// 测试Partial方法 - 验证部分应用函数功能
+ /// 测试Partial方法 - 验证部分应用函数功能
///
[Test]
public void Partial_Should_Fix_First_Argument_Of_Binary_Function()
@@ -28,7 +28,7 @@ public class FunctionExtensionsTests
}
///
- /// 测试Repeat方法 - 验证重复执行函数功能
+ /// 测试Repeat方法 - 验证重复执行函数功能
///
[Test]
public void Repeat_Should_Execute_Function_N_Times()
diff --git a/GFramework.Core.Tests/functional/pipe/PipeExtensionsTests.cs b/GFramework.Core.Tests/functional/pipe/PipeExtensionsTests.cs
index c8c0327..3db2114 100644
--- a/GFramework.Core.Tests/functional/pipe/PipeExtensionsTests.cs
+++ b/GFramework.Core.Tests/functional/pipe/PipeExtensionsTests.cs
@@ -4,14 +4,14 @@ using NUnit.Framework;
namespace GFramework.Core.Tests.functional.pipe;
///
-/// PipeExtensions扩展方法测试类,用于验证管道和函数组合扩展方法的正确性
-/// 包括管道操作、函数组合等核心功能的测试
+/// PipeExtensions扩展方法测试类,用于验证管道和函数组合扩展方法的正确性
+/// 包括管道操作、函数组合等核心功能的测试
///
[TestFixture]
public class PipeExtensionsTests
{
///
- /// 测试Also方法 - 验证执行操作后返回原值功能
+ /// 测试Also方法 - 验证执行操作后返回原值功能
///
[Test]
public void Also_Should_Execute_Action_And_Return_Original_Value()
diff --git a/GFramework.Core/coroutine/extensions/CommandCoroutineExtensions.cs b/GFramework.Core/coroutine/extensions/CommandCoroutineExtensions.cs
index 041d30e..a919458 100644
--- a/GFramework.Core/coroutine/extensions/CommandCoroutineExtensions.cs
+++ b/GFramework.Core/coroutine/extensions/CommandCoroutineExtensions.cs
@@ -20,13 +20,13 @@ using GFramework.Core.coroutine.instructions;
namespace GFramework.Core.coroutine.extensions;
///
-/// 命令协程扩展方法类
-/// 提供将命令的异步执行包装为协程的功能
+/// 命令协程扩展方法类
+/// 提供将命令的异步执行包装为协程的功能
///
public static class CommandCoroutineExtensions
{
///
- /// 将 Command 的异步执行包装为协程,并处理异常
+ /// 将 Command 的异步执行包装为协程,并处理异常
///
/// 命令类型,必须实现 IAsyncCommand 接口
/// 上下文感知对象
@@ -43,14 +43,11 @@ public static class CommandCoroutineExtensions
yield return task.AsCoroutineInstruction();
- if (task.IsFaulted)
- {
- onError?.Invoke(task.Exception!);
- }
+ if (task.IsFaulted) onError?.Invoke(task.Exception!);
}
///
- /// 发送 Command 并等待指定 Event
+ /// 发送 Command 并等待指定 Event
///
/// 命令类型,必须实现 IAsyncCommand 接口
/// 事件类型
@@ -89,10 +86,8 @@ public static class CommandCoroutineExtensions
// 检查是否超时
if (timeoutWait.IsTimeout)
- {
// 超时处理
throw new TimeoutException($"wait for the event ${typeof(TEvent).Name} timeout.");
- }
}
else
{
@@ -101,10 +96,7 @@ public static class CommandCoroutineExtensions
}
// 调用事件回调
- if (onEvent != null && wait.EventData != null)
- {
- onEvent.Invoke(wait.EventData);
- }
+ if (onEvent != null && wait.EventData != null) onEvent.Invoke(wait.EventData);
}
finally
{
diff --git a/GFramework.Core/coroutine/extensions/CoroutineComposeExtensions.cs b/GFramework.Core/coroutine/extensions/CoroutineComposeExtensions.cs
index 8ca8114..b0baead 100644
--- a/GFramework.Core/coroutine/extensions/CoroutineComposeExtensions.cs
+++ b/GFramework.Core/coroutine/extensions/CoroutineComposeExtensions.cs
@@ -16,12 +16,12 @@ using GFramework.Core.Abstractions.coroutine;
namespace GFramework.Core.coroutine.extensions;
///
-/// 提供协程组合扩展方法的静态类
+/// 提供协程组合扩展方法的静态类
///
public static class CoroutineComposeExtensions
{
///
- /// 将一个协程枚举器与一个动作组合,先执行完第一个协程,然后执行指定的动作
+ /// 将一个协程枚举器与一个动作组合,先执行完第一个协程,然后执行指定的动作
///
/// 第一个协程枚举器
/// 在第一个协程完成后要执行的动作
@@ -39,7 +39,7 @@ public static class CoroutineComposeExtensions
}
///
- /// 将两个协程枚举器顺序组合,先执行完第一个协程,再执行第二个协程
+ /// 将两个协程枚举器顺序组合,先执行完第一个协程,再执行第二个协程
///
/// 第一个协程枚举器
/// 第二个协程枚举器
diff --git a/GFramework.Core/coroutine/extensions/QueryCoroutineExtensions.cs b/GFramework.Core/coroutine/extensions/QueryCoroutineExtensions.cs
index 27f12dd..ef7d048 100644
--- a/GFramework.Core/coroutine/extensions/QueryCoroutineExtensions.cs
+++ b/GFramework.Core/coroutine/extensions/QueryCoroutineExtensions.cs
@@ -18,13 +18,13 @@ using GFramework.Core.Abstractions.rule;
namespace GFramework.Core.coroutine.extensions;
///
-/// 查询协程扩展方法类
-/// 提供将查询操作包装为协程的扩展方法
+/// 查询协程扩展方法类
+/// 提供将查询操作包装为协程的扩展方法
///
public static class QueryCoroutineExtensions
{
///
- /// 将 Query 包装为协程(立即返回结果)
+ /// 将 Query 包装为协程(立即返回结果)
///
/// 查询类型,必须实现 IQuery<TResult> 接口
/// 查询结果类型
diff --git a/GFramework.Core/coroutine/instructions/WaitForEvent.cs b/GFramework.Core/coroutine/instructions/WaitForEvent.cs
index b267c0a..c84d244 100644
--- a/GFramework.Core/coroutine/instructions/WaitForEvent.cs
+++ b/GFramework.Core/coroutine/instructions/WaitForEvent.cs
@@ -20,7 +20,6 @@ public sealed class WaitForEvent : IYieldInstruction, IDisposable
{
private bool _disposed;
private volatile bool _done;
- private TEvent? _eventData;
private IUnRegister? _unRegister;
///
@@ -38,7 +37,7 @@ public sealed class WaitForEvent : IYieldInstruction, IDisposable
///
/// 获取接收到的事件数据
///
- public TEvent? EventData => _eventData;
+ public TEvent? EventData { get; private set; }
///
/// 释放资源
@@ -77,7 +76,7 @@ public sealed class WaitForEvent : IYieldInstruction, IDisposable
/// 事件数据
private void OnEventTriggered(TEvent eventData)
{
- _eventData = eventData;
+ EventData = eventData;
_done = true;
}
}
\ No newline at end of file
diff --git a/GFramework.Core/coroutine/instructions/WaitForEventWithTimeout.cs b/GFramework.Core/coroutine/instructions/WaitForEventWithTimeout.cs
index 6a410a2..ce64cdd 100644
--- a/GFramework.Core/coroutine/instructions/WaitForEventWithTimeout.cs
+++ b/GFramework.Core/coroutine/instructions/WaitForEventWithTimeout.cs
@@ -16,7 +16,7 @@ using GFramework.Core.Abstractions.coroutine;
namespace GFramework.Core.coroutine.instructions;
///
-/// 带超时的事件等待指令
+/// 带超时的事件等待指令
///
/// 事件类型
/// 要包装的事件等待指令
@@ -30,31 +30,28 @@ public sealed class WaitForEventWithTimeout(WaitForEvent waitFor
private float _elapsedTime;
///
- /// 获取是否已超时
+ /// 获取是否已超时
///
public bool IsTimeout => _elapsedTime >= timeout;
///
- /// 获取接收到的事件数据
+ /// 获取接收到的事件数据
///
public TEvent? EventData => _waitForEvent.EventData;
///
- /// 获取指令是否已完成(事件已触发或超时)
+ /// 获取指令是否已完成(事件已触发或超时)
///
public bool IsDone => _waitForEvent.IsDone || IsTimeout;
///
- /// 更新指令状态
+ /// 更新指令状态
///
/// 时间增量
public void Update(double deltaTime)
{
// 只有在事件未完成时才累加经过的时间
- if (!_waitForEvent.IsDone)
- {
- _elapsedTime += (float)deltaTime;
- }
+ if (!_waitForEvent.IsDone) _elapsedTime += (float)deltaTime;
_waitForEvent.Update(deltaTime);
}
diff --git a/GFramework.Core/events/EventListenerScope.cs b/GFramework.Core/events/EventListenerScope.cs
index 6a7e186..20b917c 100644
--- a/GFramework.Core/events/EventListenerScope.cs
+++ b/GFramework.Core/events/EventListenerScope.cs
@@ -16,17 +16,16 @@ using GFramework.Core.Abstractions.events;
namespace GFramework.Core.events;
///
-/// 事件监听器作用域,用于监听特定类型的事件并在触发时提供事件数据
+/// 事件监听器作用域,用于监听特定类型的事件并在触发时提供事件数据
///
/// 要监听的事件类型
public sealed class EventListenerScope : IDisposable
{
private readonly IUnRegister? _unRegister;
- private TEvent? _eventData;
private volatile bool _triggered;
///
- /// 初始化事件监听器作用域的新实例
+ /// 初始化事件监听器作用域的新实例
///
/// 事件总线实例,用于注册事件监听器
public EventListenerScope(IEventBus eventBus)
@@ -35,17 +34,17 @@ public sealed class EventListenerScope : IDisposable
}
///
- /// 获取接收到的事件数据
+ /// 获取接收到的事件数据
///
- public TEvent? EventData => _eventData;
+ public TEvent? EventData { get; private set; }
///
- /// 获取事件是否已被触发
+ /// 获取事件是否已被触发
///
public bool IsTriggered => _triggered;
///
- /// 释放资源,取消事件监听器的注册
+ /// 释放资源,取消事件监听器的注册
///
public void Dispose()
{
@@ -53,12 +52,12 @@ public sealed class EventListenerScope : IDisposable
}
///
- /// 事件触发时的回调方法,用于存储事件数据并标记已触发状态
+ /// 事件触发时的回调方法,用于存储事件数据并标记已触发状态
///
/// 接收到的事件数据
private void OnEventTriggered(TEvent eventData)
{
- _eventData = eventData;
+ EventData = eventData;
_triggered = true;
}
}
\ No newline at end of file
diff --git a/GFramework.Core/functional/control/ControlExtensions.cs b/GFramework.Core/functional/control/ControlExtensions.cs
index 49473a8..90ebc9d 100644
--- a/GFramework.Core/functional/control/ControlExtensions.cs
+++ b/GFramework.Core/functional/control/ControlExtensions.cs
@@ -14,12 +14,12 @@
namespace GFramework.Core.functional.control;
///
-/// 控制流扩展方法类,提供函数式编程风格的控制结构
+/// 控制流扩展方法类,提供函数式编程风格的控制结构
///
public static class ControlExtensions
{
///
- /// TakeIf:条件返回值或null
+ /// TakeIf:条件返回值或null
///
/// 输入值的类型
/// 要进行条件判断的输入值
@@ -29,10 +29,12 @@ public static class ControlExtensions
this TSource value,
Func predicate)
where TSource : class
- => predicate(value) ? value : null;
+ {
+ return predicate(value) ? value : null;
+ }
///
- /// TakeUnless:条件相反的TakeIf
+ /// TakeUnless:条件相反的TakeIf
///
/// 输入值的类型
/// 要进行条件判断的输入值
@@ -42,5 +44,7 @@ public static class ControlExtensions
this TSource value,
Func predicate)
where TSource : class
- => !predicate(value) ? value : null;
+ {
+ return !predicate(value) ? value : null;
+ }
}
\ No newline at end of file
diff --git a/GFramework.Core/functional/functions/FunctionExtensions.cs b/GFramework.Core/functional/functions/FunctionExtensions.cs
index a778363..c9b38d4 100644
--- a/GFramework.Core/functional/functions/FunctionExtensions.cs
+++ b/GFramework.Core/functional/functions/FunctionExtensions.cs
@@ -16,17 +16,17 @@ using System.Collections.Concurrent;
namespace GFramework.Core.functional.functions;
///
-/// 函数式编程扩展方法集合,提供柯里化、偏函数应用、重复执行、安全执行和缓存等功能
+/// 函数式编程扩展方法集合,提供柯里化、偏函数应用、重复执行、安全执行和缓存等功能
///
public static class FunctionExtensions
{
#region Repeat
///
- /// Repeat:对值重复应用函数 n 次
+ /// Repeat:对值重复应用函数 n 次
///
///
- /// 当 times 小于 0 时抛出
+ /// 当 times 小于 0 时抛出
///
public static T Repeat(
this T value,
@@ -36,10 +36,7 @@ public static class FunctionExtensions
ArgumentOutOfRangeException.ThrowIfNegative(times);
var result = value;
- for (var i = 0; i < times; i++)
- {
- result = func(result);
- }
+ for (var i = 0; i < times; i++) result = func(result);
return result;
}
@@ -49,7 +46,7 @@ public static class FunctionExtensions
#region Try → Result
///
- /// Try:安全执行并返回 language-ext 的 Result
+ /// Try:安全执行并返回 language-ext 的 Result
///
public static Result Try(
this TSource value,
@@ -70,13 +67,12 @@ public static class FunctionExtensions
#region Memoize (Unbounded / Unsafe)
///
- /// MemoizeUnbounded:
- /// 对函数结果进行无界缓存(线程安全)
- ///
- /// ⚠ 注意:
- /// - 缓存永不释放
- /// - TSource 必须具有稳定的 Equals / GetHashCode
- /// - 仅适用于纯函数
+ /// MemoizeUnbounded:
+ /// 对函数结果进行无界缓存(线程安全)
+ /// ⚠ 注意:
+ /// - 缓存永不释放
+ /// - TSource 必须具有稳定的 Equals / GetHashCode
+ /// - 仅适用于纯函数
///
public static Func MemoizeUnbounded(
this Func func)
@@ -91,14 +87,15 @@ public static class FunctionExtensions
#region Partial (Advanced)
///
- /// Partial:部分应用(二参数函数固定第一个参数)
- ///
- /// ⚠ 偏函数应用属于高级用法,不建议在业务代码滥用
+ /// Partial:部分应用(二参数函数固定第一个参数)
+ /// ⚠ 偏函数应用属于高级用法,不建议在业务代码滥用
///
public static Func Partial(
this Func func,
T1 firstArg)
- => second => func(firstArg, second);
+ {
+ return second => func(firstArg, second);
+ }
#endregion
}
\ No newline at end of file
diff --git a/GFramework.Core/functional/pipe/PipeExtensions.cs b/GFramework.Core/functional/pipe/PipeExtensions.cs
index 5dab5d4..420ab54 100644
--- a/GFramework.Core/functional/pipe/PipeExtensions.cs
+++ b/GFramework.Core/functional/pipe/PipeExtensions.cs
@@ -14,15 +14,14 @@
namespace GFramework.Core.functional.pipe;
///
-/// 提供函数式编程中的管道和组合操作扩展方法
+/// 提供函数式编程中的管道和组合操作扩展方法
///
public static class PipeExtensions
{
///
- /// Also:
- /// 对值执行副作用操作并返回原值
- ///
- /// 适用于日志、调试、状态同步等场景
+ /// Also:
+ /// 对值执行副作用操作并返回原值
+ /// 适用于日志、调试、状态同步等场景
///
public static T Also(
this T value,
diff --git a/GFramework.Game.Abstractions/data/IDataLocation.cs b/GFramework.Game.Abstractions/data/IDataLocation.cs
index 1f8b6a6..fd3f673 100644
--- a/GFramework.Game.Abstractions/data/IDataLocation.cs
+++ b/GFramework.Game.Abstractions/data/IDataLocation.cs
@@ -16,27 +16,27 @@ using GFramework.Game.Abstractions.enums;
namespace GFramework.Game.Abstractions.data;
///
-/// 数据位置接口,定义了数据存储的位置信息和相关属性
+/// 数据位置接口,定义了数据存储的位置信息和相关属性
///
public interface IDataLocation
{
///
- /// 存储键(文件路径 / redis key / db key)
+ /// 存储键(文件路径 / redis key / db key)
///
string Key { get; }
///
- /// 存储类型(Local / Remote / Database / Memory)
+ /// 存储类型(Local / Remote / Database / Memory)
///
- StorageKind Kind { get; }
+ StorageKinds Kinds { get; }
///
- /// 命名空间/分区
+ /// 命名空间/分区
///
string? Namespace { get; }
///
- /// 扩展元数据(用于存储额外信息,如压缩、加密等)
+ /// 扩展元数据(用于存储额外信息,如压缩、加密等)
///
IReadOnlyDictionary? Metadata { get; }
}
\ No newline at end of file
diff --git a/GFramework.Game.Abstractions/data/IDataLocationProvider.cs b/GFramework.Game.Abstractions/data/IDataLocationProvider.cs
index 94b4a21..832ac02 100644
--- a/GFramework.Game.Abstractions/data/IDataLocationProvider.cs
+++ b/GFramework.Game.Abstractions/data/IDataLocationProvider.cs
@@ -16,14 +16,14 @@ using GFramework.Core.Abstractions.utility;
namespace GFramework.Game.Abstractions.data;
///
-/// 定义数据位置提供者的接口,用于获取指定类型的数据位置信息
+/// 定义数据位置提供者的接口,用于获取指定类型的数据位置信息
///
-public interface IDataLocationProvider:IUtility
+public interface IDataLocationProvider : IUtility
{
///
- /// 获取指定类型的数据位置
+ /// 获取指定类型的数据位置
///
/// 需要获取位置信息的类型
/// 与指定类型关联的数据位置对象
IDataLocation GetLocation(Type type);
-}
+}
\ No newline at end of file
diff --git a/GFramework.Game.Abstractions/data/IDataRepository.cs b/GFramework.Game.Abstractions/data/IDataRepository.cs
index a94a34c..6ecda05 100644
--- a/GFramework.Game.Abstractions/data/IDataRepository.cs
+++ b/GFramework.Game.Abstractions/data/IDataRepository.cs
@@ -21,7 +21,7 @@ namespace GFramework.Game.Abstractions.data;
public interface IDataRepository : IUtility
{
///
- /// 异步加载指定位置的数据
+ /// 异步加载指定位置的数据
///
/// 要加载的数据类型,必须实现IData接口并具有无参构造函数
/// 数据位置信息
@@ -31,7 +31,7 @@ public interface IDataRepository : IUtility
///
- /// 异步保存数据到指定位置
+ /// 异步保存数据到指定位置
///
/// 要保存的数据类型,必须实现IData接口
/// 数据位置信息
@@ -41,21 +41,21 @@ public interface IDataRepository : IUtility
where T : class, IData;
///
- /// 异步检查指定位置是否存在数据
+ /// 异步检查指定位置是否存在数据
///
/// 数据位置信息
/// 返回布尔值,表示数据是否存在
Task ExistsAsync(IDataLocation location);
///
- /// 异步删除指定位置的数据
+ /// 异步删除指定位置的数据
///
/// 数据位置信息
/// 返回异步操作任务
Task DeleteAsync(IDataLocation location);
///
- /// 异步批量保存多个数据项到各自的位置
+ /// 异步批量保存多个数据项到各自的位置
///
/// 包含数据位置和对应数据对象的可枚举集合
/// 返回异步操作任务
diff --git a/GFramework.Game.Abstractions/data/ISettingsDataRepository.cs b/GFramework.Game.Abstractions/data/ISettingsDataRepository.cs
index 6b9959f..ad7a629 100644
--- a/GFramework.Game.Abstractions/data/ISettingsDataRepository.cs
+++ b/GFramework.Game.Abstractions/data/ISettingsDataRepository.cs
@@ -14,21 +14,21 @@
namespace GFramework.Game.Abstractions.data;
///
-/// 定义设置数据仓库接口,用于管理应用程序设置数据的存储和检索
+/// 定义设置数据仓库接口,用于管理应用程序设置数据的存储和检索
///
///
-/// 该接口继承自IDataRepository,专门用于处理配置设置相关的数据操作
+/// 该接口继承自IDataRepository,专门用于处理配置设置相关的数据操作
///
public interface ISettingsDataRepository : IDataRepository
{
///
- /// 异步加载所有设置项
+ /// 异步加载所有设置项
///
///
- /// 返回一个包含所有设置键值对的字典,其中键为设置名称,值为对应的设置数据对象
+ /// 返回一个包含所有设置键值对的字典,其中键为设置名称,值为对应的设置数据对象
///
///
- /// 此方法将从数据源中异步读取所有可用的设置项,并将其组织成字典格式返回
+ /// 此方法将从数据源中异步读取所有可用的设置项,并将其组织成字典格式返回
///
Task> LoadAllAsync();
diff --git a/GFramework.Game.Abstractions/data/IVersionedData.cs b/GFramework.Game.Abstractions/data/IVersionedData.cs
index b3a8066..c4c28dd 100644
--- a/GFramework.Game.Abstractions/data/IVersionedData.cs
+++ b/GFramework.Game.Abstractions/data/IVersionedData.cs
@@ -10,23 +10,24 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
+
namespace GFramework.Game.Abstractions.data;
///
-/// 版本化数据接口,继承自IData接口
-/// 提供版本控制和修改时间跟踪功能
+/// 版本化数据接口,继承自IData接口
+/// 提供版本控制和修改时间跟踪功能
///
public interface IVersionedData : IData
{
///
- /// 获取数据的版本号
+ /// 获取数据的版本号
///
/// 当前数据的版本号,用于标识数据的版本状态
int Version { get; }
-
+
///
- /// 获取数据最后修改的时间
+ /// 获取数据最后修改的时间
///
/// DateTime类型的最后修改时间戳
DateTime LastModified { get; }
-}
+}
\ No newline at end of file
diff --git a/GFramework.Game.Abstractions/data/events/DataDeletedEvent.cs b/GFramework.Game.Abstractions/data/events/DataDeletedEvent.cs
index 7e6019c..1bb9cd5 100644
--- a/GFramework.Game.Abstractions/data/events/DataDeletedEvent.cs
+++ b/GFramework.Game.Abstractions/data/events/DataDeletedEvent.cs
@@ -17,5 +17,4 @@ namespace GFramework.Game.Abstractions.data.events;
/// 表示数据删除事件的记录类型
///
/// 数据位置信息,标识被删除数据的位置
-public sealed record DataDeletedEvent(IDataLocation Location);
-
+public sealed record DataDeletedEvent(IDataLocation Location);
\ No newline at end of file
diff --git a/GFramework.Game.Abstractions/enums/StorageKind.cs b/GFramework.Game.Abstractions/enums/StorageKinds.cs
similarity index 73%
rename from GFramework.Game.Abstractions/enums/StorageKind.cs
rename to GFramework.Game.Abstractions/enums/StorageKinds.cs
index 2318d0e..2eeadbb 100644
--- a/GFramework.Game.Abstractions/enums/StorageKind.cs
+++ b/GFramework.Game.Abstractions/enums/StorageKinds.cs
@@ -14,34 +14,34 @@
namespace GFramework.Game.Abstractions.enums;
///
-/// 存储类型枚举,用于标识不同的存储方式
-/// 此枚举使用 Flags 特性,支持位运算组合多个存储类型
+/// 存储类型枚举,用于标识不同的存储方式
+/// 此枚举使用 Flags 特性,支持位运算组合多个存储类型
///
[Flags]
-public enum StorageKind
+public enum StorageKinds
{
///
- /// 无存储类型
+ /// 无存储类型
///
None = 0,
-
+
///
- /// 本地文件系统存储
+ /// 本地文件系统存储
///
Local = 1 << 0,
-
+
///
- /// 内存存储
+ /// 内存存储
///
Memory = 1 << 1,
-
+
///
- /// 远程存储
+ /// 远程存储
///
Remote = 1 << 2,
-
+
///
- /// 数据库存储
+ /// 数据库存储
///
- Database = 1 << 3,
-}
+ Database = 1 << 3
+}
\ No newline at end of file
diff --git a/GFramework.Game.Abstractions/setting/IResetApplyAbleSettings.cs b/GFramework.Game.Abstractions/setting/IResetApplyAbleSettings.cs
index 9d9fcce..062ad08 100644
--- a/GFramework.Game.Abstractions/setting/IResetApplyAbleSettings.cs
+++ b/GFramework.Game.Abstractions/setting/IResetApplyAbleSettings.cs
@@ -14,19 +14,19 @@
namespace GFramework.Game.Abstractions.setting;
///
-/// 定义一个可重置且可应用设置的接口
-/// 该接口继承自IResettable和IApplyAbleSettings接口,组合了重置功能和应用设置功能
+/// 定义一个可重置且可应用设置的接口
+/// 该接口继承自IResettable和IApplyAbleSettings接口,组合了重置功能和应用设置功能
///
public interface IResetApplyAbleSettings : IResettable, IApplyAbleSettings
{
///
- /// 获取设置数据对象
+ /// 获取设置数据对象
///
/// ISettingsData类型的设置数据
ISettingsData Data { get; }
///
- /// 获取数据类型信息
+ /// 获取数据类型信息
///
/// 表示数据类型的Type对象
Type DataType { get; }
diff --git a/GFramework.Game.Abstractions/setting/ISettingsData.cs b/GFramework.Game.Abstractions/setting/ISettingsData.cs
index 736ed97..7aef3bb 100644
--- a/GFramework.Game.Abstractions/setting/ISettingsData.cs
+++ b/GFramework.Game.Abstractions/setting/ISettingsData.cs
@@ -17,7 +17,7 @@ using GFramework.Game.Abstractions.data;
namespace GFramework.Game.Abstractions.setting;
///
-/// 定义游戏设置数据的接口
-/// 该接口继承自IData和IResettable接口,提供数据管理和重置功能
+/// 定义游戏设置数据的接口
+/// 该接口继承自IData和IResettable接口,提供数据管理和重置功能
///
public interface ISettingsData : IResettable, IVersionedData, ILoadableFrom;
\ No newline at end of file
diff --git a/GFramework.Game.Abstractions/setting/ISettingsModel.cs b/GFramework.Game.Abstractions/setting/ISettingsModel.cs
index d27221a..f47be74 100644
--- a/GFramework.Game.Abstractions/setting/ISettingsModel.cs
+++ b/GFramework.Game.Abstractions/setting/ISettingsModel.cs
@@ -3,10 +3,10 @@
namespace GFramework.Game.Abstractions.setting;
///
-/// 设置模型接口:
-/// - 管理 Settings Data 的生命周期
-/// - 管理并编排 Settings Applicator
-/// - 管理 Settings Migration
+/// 设置模型接口:
+/// - 管理 Settings Data 的生命周期
+/// - 管理并编排 Settings Applicator
+/// - 管理 Settings Migration
///
public interface ISettingsModel : IModel
{
@@ -15,14 +15,14 @@ public interface ISettingsModel : IModel
// =========================
///
- /// 获取指定类型的设置数据(唯一实例)
+ /// 获取指定类型的设置数据(唯一实例)
///
/// 设置数据类型,必须继承自ISettingsData并具有无参构造函数
/// 指定类型的设置数据实例
T GetData() where T : class, ISettingsData, new();
///
- /// 获取所有已创建的设置数据
+ /// 获取所有已创建的设置数据
///
/// 所有已创建的设置数据集合
IEnumerable AllData();
@@ -33,7 +33,7 @@ public interface ISettingsModel : IModel
// =========================
///
- /// 注册设置应用器
+ /// 注册设置应用器
///
/// 设置数据类型,必须实现IResetApplyAbleSettings接口且具有无参构造函数
/// 要注册的设置应用器
@@ -42,7 +42,7 @@ public interface ISettingsModel : IModel
///
- /// 获取指定类型的设置应用器
+ /// 获取指定类型的设置应用器
///
/// 要获取的设置应用器类型,必须继承自IResetApplyAbleSettings
/// 设置应用器实例,如果不存在则返回null
@@ -50,7 +50,7 @@ public interface ISettingsModel : IModel
///
- /// 获取所有设置应用器
+ /// 获取所有设置应用器
///
/// 所有设置应用器的集合
IEnumerable AllApplicators();
@@ -61,7 +61,7 @@ public interface ISettingsModel : IModel
// =========================
///
- /// 注册设置迁移器
+ /// 注册设置迁移器
///
/// 要注册的设置迁移器
/// 当前设置模型实例,支持链式调用
@@ -73,19 +73,19 @@ public interface ISettingsModel : IModel
// =========================
///
- /// 初始化所有设置数据(加载 + 迁移)
+ /// 初始化所有设置数据(加载 + 迁移)
///
/// 异步操作任务
Task InitializeAsync();
///
- /// 保存所有设置数据
+ /// 保存所有设置数据
///
/// 异步操作任务
Task SaveAllAsync();
///
- /// 应用所有设置
+ /// 应用所有设置
///
/// 异步操作任务
Task ApplyAllAsync();
@@ -98,7 +98,7 @@ public interface ISettingsModel : IModel
///
- /// 重置所有设置数据与应用器
+ /// 重置所有设置数据与应用器
///
void ResetAll();
}
\ No newline at end of file
diff --git a/GFramework.Game.Abstractions/setting/data/AudioSettings.cs b/GFramework.Game.Abstractions/setting/data/AudioSettings.cs
index ba54d0b..56651ce 100644
--- a/GFramework.Game.Abstractions/setting/data/AudioSettings.cs
+++ b/GFramework.Game.Abstractions/setting/data/AudioSettings.cs
@@ -48,10 +48,7 @@ public class AudioSettings : ISettingsData
public void LoadFrom(ISettingsData source)
{
// 检查数据源是否为音频设置类型
- if (source is not AudioSettings audioSettings)
- {
- return;
- }
+ if (source is not AudioSettings audioSettings) return;
// 将源数据中的各个音量设置复制到当前对象
MasterVolume = audioSettings.MasterVolume;
diff --git a/GFramework.Game.Abstractions/setting/data/GraphicsSettings.cs b/GFramework.Game.Abstractions/setting/data/GraphicsSettings.cs
index 9d5f367..ba0bfef 100644
--- a/GFramework.Game.Abstractions/setting/data/GraphicsSettings.cs
+++ b/GFramework.Game.Abstractions/setting/data/GraphicsSettings.cs
@@ -47,10 +47,7 @@ public class GraphicsSettings : ISettingsData
public void LoadFrom(ISettingsData source)
{
// 检查源数据是否为GraphicsSettings类型,如果不是则直接返回
- if (source is not GraphicsSettings settings)
- {
- return;
- }
+ if (source is not GraphicsSettings settings) return;
// 将源设置中的属性值复制到当前对象
Fullscreen = settings.Fullscreen;
diff --git a/GFramework.Game.Abstractions/setting/data/LocalizationSettings.cs b/GFramework.Game.Abstractions/setting/data/LocalizationSettings.cs
index ff0b49f..1f11d33 100644
--- a/GFramework.Game.Abstractions/setting/data/LocalizationSettings.cs
+++ b/GFramework.Game.Abstractions/setting/data/LocalizationSettings.cs
@@ -54,10 +54,7 @@ public class LocalizationSettings : ISettingsData
///
public void LoadFrom(ISettingsData source)
{
- if (source is not LocalizationSettings settings)
- {
- return;
- }
+ if (source is not LocalizationSettings settings) return;
Language = settings.Language;
Version = settings.Version;
diff --git a/GFramework.Game/data/DataRepository.cs b/GFramework.Game/data/DataRepository.cs
index dc2d836..ccd3fd6 100644
--- a/GFramework.Game/data/DataRepository.cs
+++ b/GFramework.Game/data/DataRepository.cs
@@ -35,13 +35,8 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
throw new InvalidOperationException(
"Failed to initialize storage. No IStorage utility found in context.");
- protected override void OnInit()
- {
- _storage ??= this.GetUtility()!;
- }
-
///
- /// 异步加载指定位置的数据
+ /// 异步加载指定位置的数据
///
/// 数据类型,必须实现IData接口
/// 数据位置信息
@@ -66,7 +61,7 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
}
///
- /// 异步保存数据到指定位置
+ /// 异步保存数据到指定位置
///
/// 数据类型,必须实现IData接口
/// 数据位置信息
@@ -91,15 +86,17 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
}
///
- /// 检查指定位置的数据是否存在
+ /// 检查指定位置的数据是否存在
///
/// 数据位置信息
/// 如果数据存在返回true,否则返回false
public Task ExistsAsync(IDataLocation location)
- => Storage.ExistsAsync(location.ToStorageKey());
+ {
+ return Storage.ExistsAsync(location.ToStorageKey());
+ }
///
- /// 异步删除指定位置的数据
+ /// 异步删除指定位置的数据
///
/// 数据位置信息
public async Task DeleteAsync(IDataLocation location)
@@ -111,18 +108,20 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
}
///
- /// 异步批量保存多个数据项
+ /// 异步批量保存多个数据项
///
/// 包含数据位置和数据对象的枚举集合
public async Task SaveAllAsync(IEnumerable<(IDataLocation location, IData data)> dataList)
{
var valueTuples = dataList.ToList();
- foreach (var (location, data) in valueTuples)
- {
- await SaveAsync(location, data);
- }
+ foreach (var (location, data) in valueTuples) await SaveAsync(location, data);
if (_options.EnableEvents)
this.SendEvent(new DataBatchSavedEvent(valueTuples));
}
-}
+
+ protected override void OnInit()
+ {
+ _storage ??= this.GetUtility()!;
+ }
+}
\ No newline at end of file
diff --git a/GFramework.Game/data/UnifiedSettingsDataRepository.cs b/GFramework.Game/data/UnifiedSettingsDataRepository.cs
index bbb4b88..8a17e12 100644
--- a/GFramework.Game/data/UnifiedSettingsDataRepository.cs
+++ b/GFramework.Game/data/UnifiedSettingsDataRepository.cs
@@ -209,13 +209,9 @@ public class UnifiedSettingsDataRepository(
var key = UnifiedKey;
if (await Storage.ExistsAsync(key))
- {
_file = await Storage.ReadAsync(key);
- }
else
- {
_file = new UnifiedSettingsFile { Version = 1 };
- }
_loaded = true;
}
diff --git a/GFramework.Game/data/UnifiedSettingsFile.cs b/GFramework.Game/data/UnifiedSettingsFile.cs
index 2656947..fa50ef4 100644
--- a/GFramework.Game/data/UnifiedSettingsFile.cs
+++ b/GFramework.Game/data/UnifiedSettingsFile.cs
@@ -16,19 +16,19 @@ using GFramework.Core.Abstractions.versioning;
namespace GFramework.Game.data;
///
-/// 统一设置文件类,用于管理应用程序的配置设置
-/// 实现了版本控制接口,支持配置文件的版本管理
+/// 统一设置文件类,用于管理应用程序的配置设置
+/// 实现了版本控制接口,支持配置文件的版本管理
///
-internal sealed class UnifiedSettingsFile:IVersioned
+internal sealed class UnifiedSettingsFile : IVersioned
{
///
- /// 配置节集合,存储不同类型的配置数据
- /// 键为配置节名称,值为配置对象
+ /// 配置节集合,存储不同类型的配置数据
+ /// 键为配置节名称,值为配置对象
///
public Dictionary Sections { get; set; } = new();
-
+
///
- /// 配置文件版本号,用于版本控制和兼容性检查
+ /// 配置文件版本号,用于版本控制和兼容性检查
///
public int Version { get; set; }
-}
+}
\ No newline at end of file
diff --git a/GFramework.Game/extensions/DataLocationExtensions.cs b/GFramework.Game/extensions/DataLocationExtensions.cs
index 6a5b1e6..8d9661c 100644
--- a/GFramework.Game/extensions/DataLocationExtensions.cs
+++ b/GFramework.Game/extensions/DataLocationExtensions.cs
@@ -16,12 +16,12 @@ using GFramework.Game.Abstractions.data;
namespace GFramework.Game.extensions;
///
-/// 提供数据位置相关的扩展方法
+/// 提供数据位置相关的扩展方法
///
public static class DataLocationExtensions
{
///
- /// 将数据位置转换为存储键
+ /// 将数据位置转换为存储键
///
/// 数据位置对象
/// 格式化的存储键字符串,如果命名空间为空则返回键值,否则返回"命名空间/键值"格式
@@ -29,4 +29,4 @@ public static class DataLocationExtensions
{
return string.IsNullOrEmpty(location.Namespace) ? location.Key : $"{location.Namespace}/{location.Key}";
}
-}
+}
\ No newline at end of file
diff --git a/GFramework.Game/setting/SettingsModel.cs b/GFramework.Game/setting/SettingsModel.cs
index 7f9f6b8..997a7ed 100644
--- a/GFramework.Game/setting/SettingsModel.cs
+++ b/GFramework.Game/setting/SettingsModel.cs
@@ -114,7 +114,6 @@ public class SettingsModel(IDataLocationProvider? locationProvider,
}
foreach (var data in _data.Values)
- {
try
{
var type = data.GetType();
@@ -135,7 +134,6 @@ public class SettingsModel(IDataLocationProvider? locationProvider,
{
Log.Error($"Failed to initialize settings data: {data.GetType().Name}", ex);
}
- }
this.SendEvent(new SettingsInitializedEvent());
}
@@ -147,7 +145,6 @@ public class SettingsModel(IDataLocationProvider? locationProvider,
public async Task SaveAllAsync()
{
foreach (var data in _data.Values)
- {
try
{
var location = LocationProvider.GetLocation(data.GetType());
@@ -157,7 +154,6 @@ public class SettingsModel(IDataLocationProvider? locationProvider,
{
Log.Error($"Failed to save settings data: {data.GetType().Name}", ex);
}
- }
this.SendEvent(new SettingsSavedAllEvent());
}
@@ -168,7 +164,6 @@ public class SettingsModel(IDataLocationProvider? locationProvider,
public async Task ApplyAllAsync()
{
foreach (var applicator in _applicators)
- {
try
{
await applicator.Value.Apply();
@@ -177,7 +172,6 @@ public class SettingsModel(IDataLocationProvider? locationProvider,
{
Log.Error($"Failed to apply settings: {applicator.GetType().Name}", ex);
}
- }
this.SendEvent(new SettingsAppliedAllEvent());
}
@@ -207,7 +201,7 @@ public class SettingsModel(IDataLocationProvider? locationProvider,
}
///
- /// 获取指定类型的设置应用器
+ /// 获取指定类型的设置应用器
///
/// 要获取的设置应用器类型,必须继承自IResetApplyAbleSettings
/// 设置应用器实例,如果不存在则返回null
diff --git a/GFramework.Game/storage/FileStorage.cs b/GFramework.Game/storage/FileStorage.cs
index fd35bbe..20dd397 100644
--- a/GFramework.Game/storage/FileStorage.cs
+++ b/GFramework.Game/storage/FileStorage.cs
@@ -1,5 +1,4 @@
-using System.Collections.Concurrent;
-using System.IO;
+using System.IO;
using System.Text;
using GFramework.Core.Abstractions.serializer;
using GFramework.Game.Abstractions.storage;