Tech.Core
1.2.1
See the version list below for details.
dotnet add package Tech.Core --version 1.2.1
NuGet\Install-Package Tech.Core -Version 1.2.1
<PackageReference Include="Tech.Core" Version="1.2.1" />
<PackageVersion Include="Tech.Core" Version="1.2.1" />
<PackageReference Include="Tech.Core" />
paket add Tech.Core --version 1.2.1
#r "nuget: Tech.Core, 1.2.1"
#:package Tech.Core@1.2.1
#addin nuget:?package=Tech.Core&version=1.2.1
#tool nuget:?package=Tech.Core&version=1.2.1
Tech.Core
<div align="center">
高性能 .NET 基础设施工具库
</div>
简介
Tech.Core 是一个基于 .NET 10 的高性能工具库,提供经过优化的基础设施组件,帮助开发者构建高效的应用程序。所有代码采用中文注释,便于阅读和维护。
核心模块
| 模块 | 功能 | 文档 |
|---|---|---|
| Tech.Memory | 智能内存管理,自动选择最优分配策略 | 文档 |
| Tech.Caching | 多策略缓存实现,支持 LRU、LFU、FIFO、MRU | 文档 |
| Tech.Threading | 并行执行工具,提供简化的并行操作 API | 文档 |
| Tech.Guids | 顺序 GUID 生成器,优化数据库索引性能 | 文档 |
| Tech.Dynamic | 动态字典,线程安全的属性访问容器 | 文档 |
| Tech.Text | JSON 序列化,高性能字节流 API | 文档 |
| Tech.Diagnostics | 诊断工具和事件处理扩展 | 文档 |
| Tech.Collections | 高性能集合扩展方法 | 文档 |
| Tech.Utils | 实用工具类(GZip 压缩等) | 文档 |
特性
- 零拷贝操作 - 使用
Span<T>和Memory<T>实现高效数据处理 - 线程安全 - 缓存模块使用
ReaderWriterLockSlim,动态字典基于ConcurrentDictionary - 内存池化 - 减少大对象堆压力,降低 GC 开销
- 策略模式 - 灵活的缓存淘汰策略(LRU/LFU/FIFO/MRU)
- 顺序 GUID - 基于时间戳的 GUID 生成,减少数据库索引碎片
- 高性能 JSON - 字节流 API 实现 20-30% 性能提升
- 类型转换缓存 - 静态元信息缓存,实现 5-20x 类型转换性能提升
- 现代化 API - 充分利用 .NET 10 特性
- 中文注释 - 所有公共 API 均提供详细的中文 XML 注释
- 完整测试 - 660+ 单元测试覆盖所有核心功能
安装
dotnet add package Tech.Core
快速开始
内存管理
using Tech.Memory;
// 自动选择策略:小数组直接分配,大数组使用池化
using var array = new MemoryArray<byte>(4096);
array.Span.Fill(0xFF);
// 零拷贝切片操作
var slice = array.Memory.Slice(100, 200);
// LINQ 支持
var evenNumbers = array.Where(x => x % 2 == 0).ToArray();
缓存使用
using Tech.Caching;
// 创建 LRU 缓存
var cache = CacheFactory.CreateLRU<string, int>(100);
cache.Set("key", 42);
if (cache.TryGet("key", out var value))
{
Console.WriteLine(value); // 输出: 42
}
顺序 GUID
using Tech.Guids;
// 使用默认配置(SequentialAtEnd,适用于 SqlServer)
var guid = SequentialGuid.NewGuid();
// 数据库专用方法
var sqlServerGuid = SequentialGuid.NewGuidForSqlServer();
var mysqlGuid = SequentialGuid.NewGuidForMySql();
var postgreSqlGuid = SequentialGuid.NewGuidForPostgreSql();
var oracleGuid = SequentialGuid.NewGuidForOracle();
// 或使用 GuidGenerator 指定类型
var customGuid = GuidGenerator.NewGuid(GuidType.SequentialAsString);
GZip 压缩
using Tech.Utils;
// 压缩字符串
var compressed = GZip.Compress("Hello, World!");
var decompressed = GZip.Decompress(compressed);
// 压缩字节数组
byte[] data = GetData();
var compressedData = GZip.Compress(data);
var decompressedData = GZip.Decompress(compressedData);
动态字典
using Tech.Dynamic;
// 动态属性访问
dynamic dict = new DynamicDictionary();
dict.Name = "张三";
dict.Age = 25;
// 大小写不敏感
var name = dict.GetValueOrDefault<string>("name"); // "张三"
var age = dict.GetValueOrDefault<int>("AGE"); // 25
// 线程安全操作
dict.GetOrAdd("Counter", 1);
dict.AddOrUpdate("Counter", 1, (k, v) => v + 1);
// JSON 序列化支持
var json = JSON.Serialize(dict);
var deserialized = JSON.Deserialize<DynamicDictionary>(json);
JSON 序列化
using Tech.Text;
// 字符串序列化
var json = JSON.Serialize(obj);
// 高性能字节流 API(20-30% 性能提升)
byte[] jsonBytes = JSON.SerializeToUtf8Bytes(obj);
var deserialized = JSON.DeserializeFromUtf8Bytes<MyType>(jsonBytes);
// 异步 API
await JSON.SerializeAsync(stream, obj);
await JSON.DeserializeFromUtf8BytesAsync(stream);
// 扩展方法
string json = myObj.ToJson();
byte[] bytes = myObj.ToJsonBytes();
MyType obj = jsonString.ToObject<MyType>();
并行执行
using Tech.Threading;
// 并行循环
Parallel.For(0, 100, i =>
{
ProcessItem(i);
});
// 批量并行处理
Parallel.ForBatched(0, 1000, 100, (start, end) =>
{
// 每批处理 100 个元素
for (int i = start; i < end; i++)
ProcessItem(i);
});
// 并行映射转换
var source = new[] { 1, 2, 3, 4, 5 };
var results = Parallel.Map(source, x => x * x);
集合扩展
using Tech.Collections;
// 快速计数(避免 LINQ 枚举)
int[] array = { 1, 2, 3, 4, 5 };
int count = array.FastCount(); // O(1),直接访问 Length
// 高性能分块
IEnumerable<int> numbers = Enumerable.Range(1, 100);
foreach (var chunk in numbers.FastChunk(10))
{
Console.WriteLine(string.Join(", ", chunk.Span));
}
文档
详细 API 文档和更多示例,请访问:
| 文档 | 描述 |
|---|---|
| 内存管理 | MemoryArray、自动策略选择、零拷贝操作 |
| 缓存 | 多策略缓存、线程安全、淘汰策略 |
| 并行执行 | Parallel 静态类、批量处理、并行映射 |
| GUID 生成器 | 顺序 GUID、数据库优化 |
| 动态字典 | DynamicDictionary、动态属性访问、类型转换 |
| JSON 序列化 | 高性能 JSON API、字节流序列化 |
| 诊断工具 | 泛型事件参数、事件扩展、命令执行器 |
| 集合扩展 | FastCount、FastChunk 高性能集合操作 |
| 实用工具 | GZip 压缩/解压缩 |
项目结构
Tech.Core/
├── src/
│ └── Tech.Core/ # 主项目
│ └── Tech/
│ ├── Memory/ # 内存管理模块
│ ├── Caching/ # 缓存模块
│ ├── Threading/ # 并行执行模块
│ ├── Guids/ # GUID 生成器模块
│ ├── Dynamic/ # 动态字典模块
│ ├── Text/ # JSON 序列化模块
│ ├── Diagnostics/ # 诊断工具模块
│ ├── Collections/ # 集合扩展模块
│ └── Utils/ # 实用工具模块
├── tests/
│ └── Tech.Tests/ # 单元测试 (660+ 测试用例)
├── samples/
│ └── Tech.Samples/ # 示例代码
├── docs/ # 文档
└── scripts/ # 构建脚本
运行示例
# 运行示例程序
dotnet run --project samples/Tech.Samples
# 运行测试
dotnet test
# 构建项目
dotnet build
性能
Tech.Core 经过性能优化:
- 内存管理: 使用 ArrayPool 减少分配开销,零拷贝操作避免内存复制
- 缓存并发: ReaderWriterLockSlim 支持多读单写,原子时间戳避免锁升级
- GUID 生成: 基于时间戳的顺序生成,减少数据库索引碎片
- 压缩: GZip 流式压缩,支持大数据处理
版本历史
1.2.0
- 构建系统优化
- 改进构建脚本,增强自动化打包流程
- 新增 NuGet 推送脚本
- 优化项目配置管理
1.1.0
- 初始版本
- Tech.Memory 模块 - 自动策略内存数组
- Tech.Caching 模块 - 支持 LRU、LFU、FIFO、MRU 淘汰策略
- Tech.Threading 模块 - 并行执行器
- Tech.Guids 模块 - 顺序 GUID 生成器
- Tech.Diagnostics 模块 - 泛型事件参数、命令执行器
- Tech.Collections 模块 - FastCount、FastChunk 扩展方法
- Tech.Utils 模块 - GZip 压缩/解压缩
1.1.0
- 新增 Tech.Dynamic 模块 - 动态字典(DynamicDictionary)
- 不区分大小写的键访问
- 线程安全的并发操作
- 自动类型转换(支持枚举、可空类型等)
- 高性能静态缓存(5-20x 性能提升)
- JSON 序列化支持
- 新增 Tech.Text 模块 - JSON 序列化
- 简化的 JSON API
- 高性能字节流序列化(20-30% 性能提升)
- 自定义 DateTime 格式转换器
- 异步流式 API
贡献
欢迎贡献!请随时提交 Issue 或 Pull Request。
开发指南
项目配置:
- 警告即错误:
TreatWarningsAsErrors=true - 启用代码风格:
EnforceCodeStyleInBuild=true - 可空引用类型:
Nullable=enable - 语言版本: .NET 10 latest
- 中性语言: zh-CN(中文注释)
许可证
Copyright (c) 2026 Tech
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- CommunityToolkit.Diagnostics (>= 8.4.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Tech.Core:
| Package | Downloads |
|---|---|
|
Tech.Spatial
基于 .NET 10 的高性能基础设施组件库。 |
|
|
Tech.Numerics
基于 .NET 10 的高性能基础设施组件库。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
1.0.0 - Initial release of Tech.Core, a high-performance infrastructure component library based on .NET 10.
1.1.0 - Added new features and improvements to enhance performance and usability.
1.1.1 - Fixed minor bugs and improved documentation for better developer experience.
1.2.0 - Introduced new components and optimized existing ones for even faster performance and lower memory usage.
1.2.1 - Updated dependencies and made minor improvements to ensure compatibility with the latest .NET 10 updates.