# CsToolHub **Repository Path**: Pridejoy/cstoolhub ## Basic Information - **Project Name**: CsToolHub - **Description**: .net-tool - **Primary Language**: C# - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-13 - **Last Updated**: 2025-12-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # CsToolHub ## 介绍 - 一个cool的Net工具类库, 无需复杂配置,引入后即可通过扩展方法直接使用,能显著减少重复代码,让代码更简洁易读。根据项目需求选择合适的库组合使用,可以极大提升开发效率。 ## 安装教程 ``` ``` ## 使用说明 ### 主要功能模块 #### 1. ConsoleUtils 控制台输出工具 ```csharp ConsoleUtils.WriteLine("这是默认颜色文本"); ConsoleUtils.WriteLine("这是绿色文本", ConsoleColor.Green); ``` #### 2. ShellUtils 系统命令执行工具 ```csharp // Linux系统执行bash命令 ShellUtils.Bash("ls -l | head -3"); // Windows系统执行cmd命令 ShellUtils.Cmd("cmd.exe", "/c dir /b | findstr /n .*"); ``` #### 3. DesUtil DES加密解密工具 ```csharp string original = "测试DES加密"; string key = "12345678"; // DES密钥必须8位 string iv = "87654321"; // 向量必须8位 string encrypted = DesUtil.Encrypt(original, key, iv); string decrypted = DesUtil.Decrypt(encrypted, key, iv); ``` #### 4. StringUtils 字符串处理工具 ```csharp string testStr = " Hello World! 2024 "; Console.WriteLine($"是否为空: {testStr.IsNullOrEmpty()}"); Console.WriteLine($"是否为空白: {testStr.IsNullOrWhiteSpace()}"); Console.WriteLine($"MD5哈希: {testStr.ToMd5()}"); Console.WriteLine($"SHA256哈希: {testStr.ToSha256()}"); Console.WriteLine($"Base64编码: {testStr.ToBase64()}"); Console.WriteLine($"截断(10字符): {testStr.Truncate(10)}"); ``` #### 5. LogUtils 日志记录工具 ```csharp "这是一条同步日志".CwAndFileLog(); ``` #### 6. MathUtils 数学计算工具 ```csharp int num = 15; Console.WriteLine($"数值限制: {num.Clamp(0, 10)}"); double pi = 3.1415926535; Console.WriteLine($"四舍五入(2位): {pi.RoundTo(2)}"); ``` #### 7. ShaUtil SHA加密工具 ```csharp string shaSource = "测试SHA加密"; Console.WriteLine($"SHA1: {ShaUtil.Encrypt(shaSource, ShaUtil.ShaType.SHA1)}"); Console.WriteLine($"SHA256: {ShaUtil.Encrypt(shaSource, ShaUtil.ShaType.SHA256)}"); ``` #### 8. Md5Util MD5加密工具 ```csharp string md5Source = "测试MD5加密"; Console.WriteLine($"32位MD5: {Md5Util.Encrypt(md5Source)}"); Console.WriteLine($"16位MD5: {Md5Util.Encrypt16(md5Source)}"); ``` #### 9. ValidationUtils 数据验证工具 ```csharp string email = "test@example.com"; string phone = "13800138000"; Console.WriteLine($"邮箱验证 [{email}]: {email.IsEmail()}"); Console.WriteLine($"手机号验证 [{phone}]: {phone.IsPhoneNumber()}"); ``` #### 10. ConvertExtensions 类型转换工具 ```csharp string intStr = "123"; string doubleStr = "123.45"; Console.WriteLine($"字符串转int: {intStr.ToInt()}"); Console.WriteLine($"字符串转double: {doubleStr.ToDouble()}"); ``` #### 11. DateTimeUtils 日期时间工具 ```csharp DateTime now = DateTime.Now; Console.WriteLine($"默认格式化: {now.Format()}"); Console.WriteLine($"日期格式化: {now.ToDateString()}"); ``` #### 12. EnumExtensions 枚举处理工具 ```csharp TestEnum enumValue = TestEnum.Value1 | TestEnum.Value2; Console.WriteLine($"枚举描述: {enumValue.GetDescription()}"); Console.WriteLine($"枚举转int: {enumValue.ToInt()}"); ``` ### 更多功能 - JSON序列化/反序列化 (JsonExtensions) - 集合操作工具 (CollectionUtils) - 程序集扩展 (AssemblyExtensions) - HTTP扩展 (HttpExtensions) - AES/RSA加密 (AesUtil/RsaUtil) - 服务器信息获取 (ServerInfoUtil) 所有演示功能都可以直接在项目中使用,无需额外配置。