CgdataBase.Core 1.9.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package CgdataBase.Core --version 1.9.8
                    
NuGet\Install-Package CgdataBase.Core -Version 1.9.8
                    
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="CgdataBase.Core" Version="1.9.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CgdataBase.Core" Version="1.9.8" />
                    
Directory.Packages.props
<PackageReference Include="CgdataBase.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 CgdataBase.Core --version 1.9.8
                    
#r "nuget: CgdataBase.Core, 1.9.8"
                    
#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 CgdataBase.Core@1.9.8
                    
#: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=CgdataBase.Core&version=1.9.8
                    
Install as a Cake Addin
#tool nuget:?package=CgdataBase.Core&version=1.9.8
                    
Install as a Cake Tool

CgdataBase.Core

一个轻量级的 .NET 基础工具库,聚焦“日常开发中反复出现的小问题”:参数校验、文件系统操作、字节/文本转换、序列化、网络工具、常用扩展方法,以及一些基于 IDisposable 的作用域控制类。

该包以“零外部依赖”为目标,主要使用 .NET 自带 API 实现。

安装

Install-Package CgdataBase.Core
dotnet add package CgdataBase.Core

目标框架

  • net6.0 / net8.0 / net10.0

包含内容

Controllers(作用域/控制类)

  • BusyScope:通过 using 作用域管理“繁忙状态”,支持嵌套调用(内部使用栈计数),适合 MVVM/桌面端 UI 的 IsBusy 场景。
  • DelayInvoke:延迟执行(离开 using 代码块时执行回调),用于“收口式”的资源释放/收尾动作。
  • RingList<T>:固定容量的环形列表(追加超过容量会覆盖最旧数据),用于缓冲区/采样窗口/最近 N 条记录。
  • TempDirectoryScope:创建临时目录并在释放时自动清理;支持创建多个临时目录并统一回收,提供 MoveTo 将临时产物转移到目标位置。

Extensions(常用扩展方法)

  • 字符串:判空、格式判断(如 Email/IP)、截取、拆分、大小写比较、文件/目录存在性判断、16/2 进制文本转换、加解密便捷封装等。
  • 集合:IEnumerable/Dictionary/ConcurrentDictionary 的便捷操作(批量、判空等)。
  • 时间:DateTime / TimeSpan 的常用计算与格式化辅助。
  • 枚举:获取描述/转换等。
  • Hash:字符串/文件/流/字节数组的 MD5 便捷扩展(底层由 HashHelper 实现)。

Helpers(通用工具类)

  • 参数与条件校验
    • Guards:空值/空字符串/集合/路径/条件等快速校验,失败时抛出明确异常(支持 CallerArgumentExpression 生成参数名)。
  • 文件与路径
    • FileSystemHelper:拷贝目录、删除文件/目录、读取共享文件、路径格式转换(Windows/Linux)、相对路径计算、判断文件占用等。
    • FileHelper:文本/JSON/XML 文件读写;文件 MD5 计算。
  • 序列化
    • JsonEngine:基于 DataContractJsonSerializer 的 JSON 序列化/反序列化。
    • XmlEngine:基于 XmlSerializer 的 XML 序列化/反序列化(文件与字符串)。
  • 哈希/压缩/加密
    • HashHelper:MD5/SHA1/SHA256(字符串/文件/流/字节)。
    • GZipCompress:GZip 压缩/解压(字符串、字节数组、文件)。
    • TextEncry:AES(CBC/PKCS7) 文本加解密与简单异或加解密(适合业务层“轻量保护”,不建议用于高强度安全场景)。
  • 字节与位操作
    • ByteStringConverter:字节与 16/2 进制字符串互转,支持多种输出格式。
    • CgBitArray / CgBitConverter / StructByteConverter:位数组、字节序处理、结构体与字节数组互转等(面向协议/报文场景)。
  • 网络
    • NetworkHelper:域名解析、IP/MAC 校验与解析、Wake-on-LAN 魔术包生成与发送、获取 TcpClient 远端地址等。
    • PingHelper:对主机/IP 执行 Ping 并返回结构化结果。
  • 应用设置与基础类型
    • ApplicationSettings / UISettings:基于 JSON 文件(默认 config.json/uiconfig.json)的简易设置存取(Hashtable)。
    • NotifyPropertyClass:实现 INotifyPropertyChanged/Changing 的基础类,提供 SetProperty
    • RandomIdentifier:生成可读的随机代码标识符(类名/变量名等)。
    • WindowsOsVersion / SystemHelper:Windows 版本判断等系统相关辅助。

Interfaces(协议/约束)

  • IAppSettingsBase:定义一组常用应用设置契约(字体、离线模式、数据库配置、更新服务配置等),并附带 DatabaseType 枚举。

快速示例

1) 创建临时目录并自动清理

using CgdataBase.Core.Controllers;

using var scope = new TempDirectoryScope();
var tempDir = scope.GetTempDirectory(create: true);

var outputFile = Path.Combine(tempDir, "output.txt");
File.WriteAllText(outputFile, "hello");

2) 固定容量的最近 N 条记录

using CgdataBase.Core.Controllers;

var ring = new RingList<int>(capacity: 3);
ring.AddRange(new[] { 1, 2, 3, 4 });

var latest = ring.GetArray(); // [2, 3, 4]

3) 参数/条件校验 + 哈希

using CgdataBase.Core.Helpers;

Guards.HasValidText(userInput);
var sha256 = HashHelper.GetSHA256FromString(userInput);

4) 字节与十六进制互转

using CgdataBase.Core.Helpers;

var bytes = ByteStringConverter.ConvertHexStringToBytes("0A FF 01");
var hex = ByteStringConverter.ConvertBytesToHexString(bytes!, mode: 1); // "0A FF 01"

License

MIT

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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.
  • net10.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on CgdataBase.Core:

Package Downloads
CgdataBase.WPF

Package Description

CgdataBase.UI

Package Description

CgdataBase.Avalonia

Package Description

CgdataBase.WPF.FreeSql

Package Description

CgdataBase.Algorithm

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.9.21 105 4/15/2026
1.9.19 108 4/8/2026
1.9.16 108 4/7/2026
1.9.12 118 4/3/2026
1.9.11 121 3/25/2026
1.9.8 114 3/23/2026
1.9.7 109 3/23/2026
1.9.6 164 3/20/2026
1.9.5 114 3/19/2026
1.9.4 111 3/18/2026
1.9.3 196 1/6/2026
1.9.2 225 12/5/2025
1.9.1 293 11/22/2025
1.9.0 360 11/21/2025
1.8.3 447 11/20/2025
1.8.2 457 11/18/2025
1.8.1 439 11/18/2025
1.8.0 238 11/6/2025
1.7.19 216 11/2/2025
1.7.18 248 10/30/2025
Loading failed