Skip to content

Commit 8234064

Browse files
committed
docs: 添加 GameFrameX.Foundation.Utility 的 README 文档
添加项目 README 文档,描述通用实用工具库的功能模块和使用示例
1 parent 3a09861 commit 8234064

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# GameFrameX.Foundation.Utility
2+
3+
通用实用工具库,提供与框架无关的辅助功能。
4+
5+
## 功能模块
6+
7+
### 1. ConsoleHelper
8+
提供控制台相关的辅助功能,例如在控制台中显示不同颜色的文本。
9+
10+
**使用示例:**
11+
```csharp
12+
ConsoleHelper.WriteLine("这是一条普通消息。");
13+
ConsoleHelper.WriteInfo("这是一条信息消息。");
14+
ConsoleHelper.WriteSuccess("操作成功!");
15+
ConsoleHelper.WriteWarning("这是一个警告。");
16+
ConsoleHelper.WriteError("发生了一个错误。");
17+
```
18+
19+
### 2. EnvironmentHelper
20+
提供与应用程序运行环境相关的辅助功能。
21+
22+
**使用示例:**
23+
```csharp
24+
// 判断当前是否为开发环境
25+
if (EnvironmentHelper.IsDevelopment())
26+
{
27+
// 执行仅在开发环境中运行的代码
28+
}
29+
30+
// 获取当前环境名称
31+
string environmentName = EnvironmentHelper.GetEnvironmentName();
32+
```
33+
34+
### 3. Snowflake ID 生成器
35+
基于 Snowflake 算法的分布式唯一 ID 生成器。
36+
37+
**核心组件:**
38+
- `IdWorker`: Snowflake ID 生成器核心类。
39+
- `SnowFlakeIdHelper`: `IdWorker` 的静态封装,提供更便捷的调用方式。
40+
41+
**使用示例:**
42+
```csharp
43+
// 初始化 IdWorker (通常在应用程序启动时进行一次)
44+
// 参数:workerId, dataCenterId
45+
new IdWorker(1, 1);
46+
47+
// 生成一个新的唯一 ID
48+
long newId = SnowFlakeIdHelper.NewId;
49+
```
50+
51+
### 4. TimerHelper
52+
提供强大的时间处理功能,涵盖时间戳、日期计算、时间范围判断等。
53+
54+
**核心功能:**
55+
- **时间戳转换**: `ToTimestamp()` / `ToDateTime()`
56+
- **时间偏移**: `ToTimeOffset()`
57+
- **时间范围判断**: `IsBetween()`
58+
- **获取当前时间**: `GetCurrentTime()`
59+
- **日期计算**:
60+
- `GetDayBegin()` / `GetDayEnd()`
61+
- `GetWeekBegin()` / `GetWeekEnd()`
62+
- `GetMonthBegin()` / `GetMonthEnd()`
63+
- `GetYearBegin()` / `GetYearEnd()`
64+
- **时间差计算**: `GetTimeDifference()`
65+
66+
**使用示例:**
67+
```csharp
68+
// 获取当前时间戳
69+
long timestamp = TimerHelper.ToTimestamp(DateTime.Now);
70+
71+
// 判断某个时间是否在指定范围内
72+
bool isInRange = TimerHelper.IsBetween(DateTime.Now, startTime, endTime);
73+
74+
// 获取本周的开始和结束时间
75+
DateTime weekStart = TimerHelper.GetWeekBegin(DateTime.Now);
76+
DateTime weekEnd = TimerHelper.GetWeekEnd(DateTime.Now);
77+
```

0 commit comments

Comments
 (0)