Tech.Core 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tech.Core --version 1.0.0
                    
NuGet\Install-Package Tech.Core -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tech.Core" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tech.Core" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Tech.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tech.Core --version 1.0.0
                    
#r "nuget: Tech.Core, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tech.Core@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tech.Core&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Tech.Core&version=1.0.0
                    
Install as a Cake Tool

Tech.Core

<div align="center">

高性能 .NET 基础设施工具库

NuGet .NET License

</div>

简介

Tech.Core 是一个基于 .NET 10 的高性能工具库,提供经过优化的基础设施组件,帮助开发者构建高效的应用程序。所有代码采用中文注释,便于阅读和维护。

核心模块

模块 功能 文档
Tech.Memory 智能内存管理,自动选择最优分配策略 文档
Tech.Caching 多策略缓存实现,支持 LRU、LFU、FIFO、MRU 文档
Tech.Threading 并行执行工具,提供简化的并行操作 API 文档
Tech.Diagnostics 诊断工具和事件处理扩展 文档
Tech.Collections 高性能集合扩展方法 文档
Tech.Utils 实用工具类(GZip 压缩等) 文档

特性

  • 零拷贝操作 - 使用 Span<T>Memory<T> 实现高效数据处理
  • 线程安全 - 缓存模块使用 ReaderWriterLockSlim 支持并发访问
  • 内存池化 - 减少大对象堆压力,降低 GC 开销
  • 策略模式 - 灵活的缓存淘汰策略(LRU/LFU/FIFO/MRU)
  • 现代化 API - 充分利用 .NET 10 特性(latest LangVersion)
  • 中文注释 - 所有公共 API 均提供详细的中文 XML 注释

安装

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
}

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.Diagnostics;

// 泛型事件参数
var args = new EventArgs<int>(42);

// 事件扩展方法
EventHandler<EventArgs<string>>? handler = null;
handler.Invoke(sender, "message"); // 安全调用,即使为 null 也不会抛出异常

// 命令执行器
using var cmd = new Cmd("dotnet", "--version");
cmd.Start();
cmd.WaitForExit();

并行执行

using Tech.Threading;

// 并行循环
Parallel.For(0, 100, i =>
{
    ProcessItem(i);
});

// 并行遍历
var items = new[] { 1, 2, 3, 4, 5 };
Parallel.ForEach(items, item =>
{
    ProcessItem(item);
});

// 批量并行处理
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);

// 并行执行多个操作
Parallel.Invoke(
    () => Task1(),
    () => Task2(),
    () => Task3()
);

集合扩展

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 静态类、批量处理、并行映射
诊断工具 泛型事件参数、事件扩展、命令执行器
集合扩展 FastCount、FastChunk 高性能集合操作
实用工具 GZip 压缩/解压缩

项目结构

Tech.Core/
├── src/
│   └── Tech.Core/          # 主项目
│       └── Tech/
│           ├── Memory/     # 内存管理模块
│           ├── Caching/    # 缓存模块
│           ├── Threading/  # 并行执行模块
│           ├── Diagnostics/# 诊断工具模块
│           ├── Collections/ # 集合扩展模块
│           └── Utils/      # 实用工具模块
├── tests/
│   └── Tech.Tests/         # 单元测试
├── samples/
│   └── Tech.Samples/       # 示例代码
├── docs/                   # 文档
└── scripts/                # 构建脚本

运行示例

# 运行示例程序
dotnet run --project samples/Tech.Samples

# 运行测试
dotnet test

# 构建项目
dotnet build

性能

Tech.Core 经过性能优化:

  • 内存管理: 使用 ArrayPool 减少分配开销,零拷贝操作避免内存复制
  • 缓存并发: ReaderWriterLockSlim 支持多读单写,原子时间戳避免锁升级
  • 压缩: GZip 流式压缩,支持大数据处理

版本历史

1.0.0

  • 初始版本
  • Tech.Memory 模块 - 自动策略内存数组
  • Tech.Caching 模块 - 支持 LRU、LFU、FIFO、MRU 淘汰策略
  • Tech.Threading 模块 - 并行执行器
  • Tech.Diagnostics 模块 - 泛型事件参数、命令执行器
  • Tech.Collections 模块 - FastCount、FastChunk 扩展方法
  • Tech.Utils 模块 - GZip 压缩/解压缩

贡献

欢迎贡献!请随时提交 Issue 或 Pull Request。

开发指南

项目配置:

  • 警告即错误: TreatWarningsAsErrors=true
  • 启用代码风格: EnforceCodeStyleInBuild=true
  • 可空引用类型: Nullable=enable
  • 语言版本: .NET 10 latest
  • 中性语言: zh-CN(中文注释)

许可证

MIT License

Copyright (c) 2025 Tech.Core

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
2026.4.6 119 4/6/2026
2026.4.4 111 4/4/2026
1.2.1 101 3/30/2026
1.2.0 100 3/30/2026
1.1.1 98 3/30/2026
1.1.0 103 3/29/2026
1.0.0 168 3/28/2026