CCITU.Common 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CCITU.Common --version 2.1.0                
NuGet\Install-Package CCITU.Common -Version 2.1.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="CCITU.Common" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CCITU.Common --version 2.1.0                
#r "nuget: CCITU.Common, 2.1.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.
// Install CCITU.Common as a Cake Addin
#addin nuget:?package=CCITU.Common&version=2.1.0

// Install CCITU.Common as a Cake Tool
#tool nuget:?package=CCITU.Common&version=2.1.0                

依赖包:已安装

Install-Package Microsoft.Extensions.Configuration -Version 6.0.0
Install-Package Microsoft.Extensions.Configuration.FileExtensions -Version 6.0.0
Install-Package Microsoft.Extensions.Configuration.Json -Version 6.0.0
Install-Package Newtonsoft.Json -Version 13.0.3
Install-Package Portable.BouncyCastle -Version 1.9.0
Install-Package QRCoder -Version 1.4.3
Install-Package SharpZipLib -Version 1.0.22

扩展方法

  1. 枚举
/// <summary>
/// 返回枚举项的描述信息。
/// </summary>
/// <param name="value">要获取描述信息的枚举项。</param>
/// <returns>枚举想的描述信息。</returns>
static string GetDescription(this Enum value)
  1. 异常处理
/// <summary>
/// 当action函数返回true,会抛出指定错误消息异常,用于减少if判断
/// </summary>
static T ThrowException<T>(this T value, Func<T, bool> action, string errorMessage, ExceptionTypeEnum exceptionTypeEnum = ExceptionTypeEnum.Exception)
  1. List集合
 /// <summary>
/// 转换成分页模型
/// </summary>
/// <typeparam name="T">泛型集合类型</typeparam>
/// <param name="list"></param>
/// <param name="totalRecord">总记录数</param>
/// <returns></returns>
static PaginationCollection<T> ToPaginationCollection<T>(this IEnumerable<T> list, int totalRecord)

/// <summary>
/// 排序
/// </summary>
/// <typeparam name="TSource">泛型集合类型</typeparam>
/// <typeparam name="TKey">排序属性类型</typeparam>
/// <param name="list"></param>
/// <param name="order">排序属性</param>
/// <param name="sortBy">排序类型:0=降序,1=升序</param>
/// <param name="defaultOrder">默认排序:当排序属性为null|空时使用默认排序</param>
/// <returns></returns>
static IEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> list, string order, SortByEnum sortBy, Func<TSource, TKey> defaultOrder)

辅助工具类

  • ActionResponse:构造统一的返回结果
    /// <summary>
    /// 创建结果
    /// </summary>
    /// <typeparam name="T">数据类型</typeparam>
    /// <param name="data">数据</param>
    /// <param name="message">文本消息</param>
    /// <param name="success">是否执行成功</param>
    /// <param name="code">状态码</param>
    /// <returns></returns>
    static ActionResponseResult<T> CreateResult<T>(T data, string message = "", bool success = true, int code = 200)
    
    /// <summary>
    /// 创建失败结果
    /// </summary>
    static ActionResponseResult<object> Fail(string message, int code = 400)
    static ActionResponseResult<T> Fail<T>(string message, int code = 400)
    
    /// <summary>
    /// 创建成功结果
    /// </summary>
    static ActionResponseResult<T> Success<T>(T data, string message = "", int code = 200)
    
    /// <summary>
    /// 创建成功结果:分页集合
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="data">分页集合</param>
    static ActionResponseResult<PaginationCollection<T>> Success<T>(PaginationCollection<T> data, string message = "", int code = 200)
    
    返回值ActionResponseResult<T>说明:
    /// 返回结果
    /// <typeparam name="T">数据源类型</typeparam>
    public class ActionResponseResult<T>
    {
        /// 是否成功
        public bool Success { get; set; }
        /// 状态码
        public int ResultCode { get; set; }
        /// 描述信息
        public string Message { get; set; }
        /// 数据源
        public T Tag { get; set; }
        /// 总数
        public int TotalRecord { get; set; }
    }
    
  • Pagination:数据分页模型类
    /// 页码:默认值1
    int? PageIndex { get; set; }
    /// 页大小:默认值20
    int? PageSize { get; set; }
    /// 排序字段
    string ORDER { get; set; }
    /// 排序类型:0=降序,1=升序
    SortByEnum ORDERBY { get; set; }
    
  • PaginationSearchTime继承Pagination:数据分页模型类包含搜索时间
    //开始时间字符串
    string StartTimeStr { get; set; }
    //结束时间字符串
    string EndTimeStr { get; set; }
    //开始时间
    [JsonIgnore]
    DateTime StartTime { get; }
    //结束时间:如果结束时间字符串没传时分秒,返回的时分秒是23:59:59
    [JsonIgnore]
    DateTime EndTime { get; }
    
  • CryptoUtil:加密工具:用于哈希算法(计算SHA-256、计算MD5)、签名算法(HMAC签名)
    /// <summary>
    /// 计算SHA-256
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    static string ComputeSHA256(string input)
    
    /// <summary>
    /// 计算MD5
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    static string ComputeMD5(string input)
    
    /// <summary>
    /// HMAC签名
    /// </summary>
    /// <param name="input"></param>
    /// <param name="key">密钥</param>
    /// <returns></returns>
    static string ComputeHMAC(string input, string key)
    
  • AESHelper:对称加密
    /// <summary>  
    /// AES加密  
    /// </summary>  
    /// <param name="input">明文字符串</param>  
    /// <param name="key">密钥</param>  
    /// <returns>加密后的Base64</returns>  
    static string Encrypt(string input, string key)
    
    /// <summary>  
    /// AES解密  
    /// </summary>  
    /// <param name="input">密文字符串</param>  
    /// <param name="key">密钥</param>  
    /// <returns>返回解密后的字符串</returns>  
    static string Decrypt(string input, string key)
    
  • RSAHelper:非对称加密
    /// <summary>
    /// 生成PEM格式的公钥和密钥
    /// </summary>
    /// <param name="strength">长度</param>
    /// <returns>Item1:公钥;Item2:私钥;</returns>
    static (string, string) CreateKeyPair(int strength = 1024)
    
    /// <summary>
    /// RSA解密
    /// </summary>
    /// <param name="privateKey">私钥</param>
    /// <param name="decryptstring">待解密的字符串(Base64)</param>
    /// <returns>解密后的字符串</returns>
    static string Decrypt(string privateKey, string decryptstring)
    
    /// <summary>
    /// 加密
    /// </summary>
    /// <param name="publicKey">公钥</param>
    /// <param name="encryptstring">待加密的字符串</param>
    /// <returns>加密后的Base64</returns>
    static string Encrypt(string publicKey, string encryptstring)
    
  • ConfigHelper:配置文件
    /// <summary>
    /// 读取
    /// </summary>
    /// <param name="name">文件名称</param>
    /// <param name="extension">扩展名称:默认json</param>
    /// <param name="path">文件路径:默认AppContext.BaseDirectory</param>
    /// <returns></returns>
    static IConfiguration Get(string name = "appsettings", string extension = "json", string path = null)
    
  • IPAddressApi:IP地址相关api
    /// <summary>
    /// 根据IP地址获取国家
    /// </summary>
    /// <param name="IP"></param>
    /// <returns></returns>
    static string GetCountryByIP(string IP)
    
  • QRCodeHelper:生成、合成二维码图片
    /// <summary>
    /// 生成二维码图片
    /// </summary>
    /// <param name="data">数据</param>
    /// <param name="logoUrl">logo图片地址</param>
    /// <param name="color">颜色:默认黑色</param>
    /// <param name="backgroundColor">背景色:默认白色</param>
    /// <param name="pixelsPerModule">每块像素大小:一共有45块</param>
    /// <returns></returns>
    static Image GenerateQRCode(string data, string logoUrl = null, string color = "#000", string backgroundColor = "#FFF", int pixelsPerModule = 4)
    
    /// <summary>
    /// 生成文字图片
    /// </summary>
    /// <param name="text">文字</param>
    /// <param name="width"></param>
    /// <param name="height">行高</param>
    /// <param name="fontSize">字号</param>
    /// <param name="fontColor">字体颜色</param>
    /// <returns></returns>
    static Image GenerateTextImage(string text, int width, int height, float fontSize, string fontColor)
    
    /// <summary>
    /// 合并图片
    /// </summary>
    /// <param name="imgs">图片集合</param>
    /// <param name="margin">边距</param>
    /// <returns></returns>
    static Image CombineImage(List<Image> imgs, int margin = 0)
    
  • RandomHelper:生成指定长度的随机数
    /// <summary>
    /// 生成随机数
    /// </summary>
    /// <param name="length"></param>
    /// <returns></returns>
    static string Generate(int length)
    

长整型转字符串LongToStringConverter

在配置服务容器中添加以下代码
public override void ConfigureServices(ServiceConfigurationContext context)
{
    var services = context.Services;
    services.AddNewtonsoftJson(options =>
    {
        //长整型序列化为字符串
        options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
        options.SerializerSettings.Converters.Add(new ABP.Common.LongToStringConverter());
    });
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CCITU.Common:

Package Downloads
CCITU.Middleware

Package description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.1 193 10/23/2024
2.1.0 135 10/14/2024
2.0.9 169 9/19/2024
2.0.8 355 5/29/2024
2.0.7 1,163 11/2/2023
2.0.6 313 8/26/2023
2.0.5 154 8/25/2023
2.0.4 171 8/15/2023
2.0.3 335 8/4/2023
2.0.2 230 8/4/2023
2.0.1 223 6/9/2023
2.0.0 218 6/8/2023
1.0.0 228 6/7/2023