MasterServer.Lib.Utils 1.0.3

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

Automation.Lib.Utils

通用工具类库,提供常用的工具方法和扩展功能。 作者邮箱:dengjianhua1999@qq.com

特性

  • 加密解密工具(MD5, Base64, AES等)
  • 枚举操作工具
  • 反射操作工具(深拷贝、属性操作等)
  • 序列化工具(JSON, XML)
  • 结果信息封装
  • 类型转换和验证

核心组件

1. EncryptUtils

加密解密工具类,提供:

  • MD5哈希: ComputeMD5(string input)
  • Base64编码解码: ToBase64(), FromBase64()
  • AES加密解密: EncryptAES(), DecryptAES()
  • RSA加密解密: EncryptRSA(), DecryptRSA()

2. EnumUtils

枚举操作工具类,提供:

  • 解析枚举: Parse<T>() - 获取枚举键值对列表
  • 获取描述: GetDescription() - 获取枚举项的Description特性
  • 字符串转换: ParseFromString<T>() - 从字符串解析枚举

3. ReflectionUtils

反射操作工具类,提供:

  • 深拷贝: DeepCopyProperties() - 对象属性深拷贝
  • 属性操作: GetPropertyValue(), SetPropertyValue()
  • 类型检查: IsSimpleType(), IsCollectionType()

4. Serializer

序列化工具类,提供:

  • JSON序列化: ToJson(), FromJson()
  • XML序列化: ToXml(), FromXml()
  • 二进制序列化: ToBinary(), FromBinary()

5. ResultInfo<T>

结果信息封装类,提供:

  • 成功结果: Success(T data, string message)
  • 失败结果: Fail(string message, int code)
  • 统一结果处理: 包含状态码、消息和数据

使用方式

1. 加密解密

using Automation.Lib.Utils;

// MD5哈希
string hash = EncryptUtils.ComputeMD5("password");

// Base64编码
string encoded = EncryptUtils.ToBase64("Hello World");
string decoded = EncryptUtils.FromBase64(encoded);

// AES加密
string key = "your-secret-key";
string encrypted = EncryptUtils.EncryptAES("sensitive data", key);
string decrypted = EncryptUtils.DecryptAES(encrypted, key);

2. 枚举操作

public enum UserStatus
{
    [Description("活跃用户")]
    Active = 1,
    
    [Description("禁用用户")]
    Disabled = 2
}

// 解析枚举
var enumList = EnumUtils.Parse<UserStatus>();
// 返回: [{1, "活跃用户"}, {2, "禁用用户"}]

// 从字符串解析
UserStatus status = EnumUtils.ParseFromString<UserStatus>("Active");

3. 反射操作

// 深拷贝对象
var source = new MyClass { Name = "Test", Value = 123 };
var target = new MyClass();
ReflectionUtils.DeepCopyProperties(source, target);

// 获取属性值
object value = ReflectionUtils.GetPropertyValue(obj, "PropertyName");

4. 序列化

var data = new { Name = "Test", Value = 123 };

// JSON序列化
string json = Serializer.ToJson(data);
var deserialized = Serializer.FromJson<MyClass>(json);

// XML序列化
string xml = Serializer.ToXml(data);
var fromXml = Serializer.FromXml<MyClass>(xml);

5. 结果封装

// 成功结果
ResultInfo<string> success = ResultInfo<string>.Success("操作成功", "数据内容");

// 失败结果
ResultInfo<string> fail = ResultInfo<string>.Fail("操作失败", 500);

// 检查结果
if (result.IsSuccess)
{
    Console.WriteLine(result.Message);
    var data = result.Data;
}

安装

通过NuGet安装:

Install-Package Automation.Lib.Utils

依赖

  • System.ComponentModel
  • System.Reflection
  • System.Runtime.Serialization
  • Newtonsoft.Json (可选,用于JSON序列化)</content> <parameter name="filePath">d:\work\C#Work\2025\automationlib2\Automation.Lib.Utils\README.md
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 101 4/23/2026
1.0.3 119 3/31/2026
1.0.2 194 12/25/2025
1.0.1 193 11/26/2025
1.0.0 688 11/26/2025