VinBen.Tool 0.0.1.7

dotnet add package VinBen.Tool --version 0.0.1.7
                    
NuGet\Install-Package VinBen.Tool -Version 0.0.1.7
                    
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="VinBen.Tool" Version="0.0.1.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VinBen.Tool" Version="0.0.1.7" />
                    
Directory.Packages.props
<PackageReference Include="VinBen.Tool" />
                    
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 VinBen.Tool --version 0.0.1.7
                    
#r "nuget: VinBen.Tool, 0.0.1.7"
                    
#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 VinBen.Tool@0.0.1.7
                    
#: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=VinBen.Tool&version=0.0.1.7
                    
Install as a Cake Addin
#tool nuget:?package=VinBen.Tool&version=0.0.1.7
                    
Install as a Cake Tool

关于

Vin.Tool 是 Vin.AspNetCore.Core 的工具类库,包含了一些常用的工具类。

暂不支持单文件发布,需要引用源码。参考地址:参考地址

功能

特性

  • IpAuth: 是一个Filter IP 简单访问控制,需要在 appsettings.json 中配置 IpAuth 节点,配置后仅在范围的IP可以访问改Action,配置方式如下:
{
  "Vin": {
    "IpAuth": {
      // 选其中一个使用
      // 白名单
      "WhiteList": [],
      // 黑名单
      "BlackList": []
    }
  }
}
  • InjectAttribute: 一个属性注入特性,用于标记需要注入的属性.
[Inject] 可选参数 
1. Key:指定服务的Key
  • ServiceAttribute: 一个服务标记特性,用于标记需要注入的服务.
[Service] 可选参数 
1. Lifetime:生命周期 Transient、Scoped、Singleton
2. InterfaceType:服务实现的接口
3. InterfaceTypes:服务实现的多个接口
4. Key:指定服务的Key
5. Order:指定服务的注入顺序
  • OptionAttribute: 一个配置注入特性,用于标记需要注入的配置.
[Inject] 可选参数 
1. Key:指定配置的路径
  • IgnoreServiceAttribute: 一个忽略服务注入特性,用于标记不需要注入的服务.

  • ModelAttribute: 一个模型特性,用于标记模型的属性.

校验特性

  • ClearValueAttribute: 一个清空值特性,用于标记清空当前值.
[ClearValue] 可选参数 
1. ContainsFields:当前类包含某些字段时,清空当前值
  • StringArrayAttribute:一个字符串数组特性,用于标记传输的是字符串数组.
[StringArray] 可选参数 
1. Separator:分隔符,默认为英文逗号 ","

事件

  • ApplicationStartedEventArg: 应用启动事件参数

  • ApplicationStoppedEventArg: 应用停止事件参数

  • ApplicationStoppingEventArg: 应用停止中事件参数

VinEventManager.Register<ApplicationStoppingEventArg>((obj, e) => { });

基类

  • VinBaseService:一个基础Scoped的服务类
  • VinBaseSingletonService:一个基础Singleton的服务类
  • VinBaseTransientService:一个基础Transient的服务类
  • VinEventBackgroundService:一个事件后台服务类,当触发事件后在启动后台服务

单例

  • VinApp: 一个基础的应用单例类,在程序启动时注册,包含:ServiceProvider,Configuration,HttpContext,User等
// 属性
ServiceProvider:获取服务的提供者
MvcBuilder:获取MvcBuilder
WebApplication:获取Web应用程序
Configuration:获取配置
WebHostEnvironment:获取Web主机环境
VinInitBuilderConfig:获取初始Builder配置
VinUseApplicationConfig:获取使用Application配置
ApiResultType:获取Api响应类型
HttpContextAccessor:获取HttpContext访问器
AsyncServiceProvider:获取异步服务提供者
HttpContext:获取HttpContext
HttpContextOrNull: 获取HttpContext或者null
HaveHttpContext:是否有HttpContext
User:获取请求上下文用户

// 静态方法
SetServiceProvider:设置服务提供者
SetMvcBuilder:设置MvcBuilder
SetWebApplication:设置Web应用程序
SetConfiguration:设置配置
SetWebHostEnvironment:设置Web主机环境
SetVinInitBuilderConfig:设置初始Builder配置
SetVinUseApplicationConfig:设置使用Application配置
SetApiResultType:设置Api响应类型
HttpContextInfo:获取HttpContext信息 parseClient:是否解析客户端信息(user-agent)
SimulateHttpContext:模拟HttpContext
CreateScopeAsync:创建作用域
GetService:获取服务 serviceKey:服务Key(可选)
GetServices:获取服务
GetKeyService:获取服务
GetRequiredService:获取服务
GetRequestServiceProvider:获取请求服务提供者
GetServiceByHttpContext:获取服务
GetRequiredKeyServiceByHttpContext:获取服务
.....
AddInjectProvider:添加注入提供者
Inject:增加注入服务,不然当前类使用[Inject]特性无效
GetLogger:获取日志
GetConfig:获取配置
GetOptionsMonitor:获取配置

异常实例

  • ErrorException:异常实例 code:状态码,msg:消息(可选)
  • BusinessException:默认业务异常实例 code:状态码默认是500,msg:消息(可选)
  • UnauthorizedException:未授权异常实例 code:状态码默认是401,msg:消息(可选)

工具类

AssemblyTool: 程序集工具类

// 属性
GetProjectAssemblies:获取项目程序集
GetProjectTypes:获取GetProjectAssemblies中所有类型
GetVinAssemblies:获取Vin程序集(程序集为"Vin.","VinBen."和VinInitBuilderConfig.AssemblyNames中配置的程序集)
GetVinTypes:获取GetVinAssemblies中所有类型
// 静态方法
GetAssemblies:获取指定内容的程序集
GetAssemblies:获取包含指定名称的程序集
GetTypes:获取包含指定类型的类型
GetCallingAssembly:获取入口程序集
GetAssemblyName:获取程序集名称
GetManifestResourceNames:获取程序集资源名称
GetManifestResourceStreamAsync:获取程序集资源流
GetManifestResourceString:获取程序集资源字符串
GetManifestResourceStringAsync:获取程序集资源字符串
GetManifestResourceInfo:获取程序集资源信息

EmptyTool: 空工具类

// 静态方法
CheckIsNullOrEmpty:检查是否为空或者null,并抛出异常
CheckIsNullOrZero:检查是否为空或者null或者0,并抛出异常
CheckIsNull:检查是否为空,并抛出异常
// 字符串可用扩展
IsNullOrEmpty
IsNull
IsNotNullOrEmpty
IsNotNull
IsNullOrWhiteSpace
IsNotNullOrWhiteSpace

RegexTool: 正则工具类

// 静态方法
IsMobile:是否手机号码
IsEmail:是否邮箱
// 字符串可用扩展
IsMobile
IsEmail

ValidatorTool: 验证工具类

// 静态方法
TryOnlyValidateObject:只验证对象是否符合规则 obj:对象,validateAllProperties:是否验证所有属性(true),throwException:是否抛出异常(true)
TryValidateObject:验证对象是否符合规则 
// 泛型扩展方法
IsValidateObject:验证对象是否符合规则

基础类型的扩展方法

// object 扩展方法
IsValueType: 是否值类型
IsEnum: 是否枚举
// long 扩展方法
ToDateTime: 时间戳转日期 isMilliseconds:是否毫秒(true)
// string 扩展方法
ToUnderLine: 转下划线 isToUpper:是否大写(false)
ToMiddleLine: 转中划线 isToUpper:是否大写(false)
ToCamelCase: 转驼峰 isToUpper:首字母是否大写(false)
LatterString:从字符串的末尾获取指定长度的字符串
Format: 格式化字符串
IsBase64: 是否Base64字符串
IsBase64ByTry: 是否Base64字符串
ToDateTime: 字符串转日期
IfNull:如果为空返回默认值
// Enum 扩展方法
GetData:获取数据(值,名称)
GetName:获取名称
GetCustomAttribute:获取自定义特性(每个值上)
GetCustomEnumAttribute:获取自定义特性(枚举类上)
GetEnumMemberValue:获取EnumMemberAttribute的值

ConvertTool: 转换工具类 自行探索

DateTimeTool: 日期工具类 自行探索

TimerTool: 计时器工具类

TimestampTool: 时间戳工具类

AesEncryptTool: AES加密工具类

Md5EncryptTool: MD5加密工具类

RsaEncryptTool: RSA加密工具类

ExceptionTool:异常工具类

// 静态方法
ExceptionMessage:获取异常消息
// 扩展方法
ExceptionMessage:获取异常消息

Expression 扩展方法

GeoTool: 地理工具类

// 静态方法
CalculateDistance:计算两点之间的距离

IntPtrTool: IntPtr工具类

// 静态方法,扩展方法
IsNullOrZero:是否为空或者0

JsonTool: Json工具类

// 属性
DefaultOptions:默认配置
CamelCaseOptions:小驼峰配置
UnderLineLowerOptions:下划线小写配置
UnderLineUpperOptions:下划线大写配置
MiddleLineLowerOptions:中划线小写配置
MiddleLineUpperOptions:中划线大写配置

// 静态方法
GenerateJsonOptions:生成Json配置

// 扩展方法
ToJsonElement:json转JsonElement
ToObject:json转对象
ToJson:对象转json
ToCamelCaseObject:对象转驼峰json(小)
ToCamelCaseJson:对象转驼峰json(小)
ToUnderLineObject:对象转下划线json(小)
ToUnderLineJson:对象转下划线json(小)
ToMiddleLineObject:对象转中划线json(小)
ToMiddleLineJson:对象转中划线json(小)
    
// JsonConverter
DateConverter:日期转换器
DateTimeConverter:日期时间转换器
DateTimeNullConverter:日期时间转换器
EnumToStringConverter:枚举转字符串转换器
LongTimeToStringConverter:长整型时间转字符串转换器
LongToStringConverter:长整型转字符串转换器
ObjectToJsonStringConverter:对象转json字符串转换器

MathTool: 数学工具类 自行探索

NetTool: 网络工具类 自行探索

HttpContextTool: HttpContext工具类

// 静态方法
IsIp: 是否IP
ToCurl: 转Curl
ParserUserAgent: 解析UserAgent
// 扩展方法
GetClientUserIp: 获取客户端IP
GetClientInfo: 获取客户端信息
GetClientDetail:获取客户端详细信息
ReadToString:读取Body字符串
ReadToJson:读取Body对象(JsonElement)
ToCurl:转Curl
SetItems:设置HttpContext.Items
GetItems:获取HttpContext.Items
GenerateRequestId:生成RequestId
GetRequestId:获取RequestId

PathTool: 路径工具类

// 静态方法
DirPathCheck:目录路径检查
ExtensionCheck:扩展名检查 (判断是否是.xxx格式)

RandomTool: 随机工具类

// 静态方法
RandomInt:随机整数
RandomDouble:随机小数
RandomLong:随机长整型
RandomString:随机字符串
RandomLetter:随机字母
RandomNumber:随机数字

RandomColorTool: 随机颜色工具类

// 静态方法
RandomColor:随机颜色

StreamTool: 流工具类

// 静态方法,扩展方法
ReadToString:读取流到字符串
ReadToJson:读取流到JsonElement
Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (14)

Showing the top 5 NuGet packages that depend on VinBen.Tool:

Package Downloads
VinBen.AspNetCore.Core

Vin Core

VinBen.Extension.Cache

Package Description

VinBen.Extension.Aop

Package Description

VinBen.Extension.SqlSugar

Package Description

VinBen.Extension.Exception

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1.7 972 11/21/2025
0.0.1.6 823 11/5/2025
0.0.1.5 732 7/11/2025
0.0.1.4 733 3/17/2025
0.0.1.3 683 9/12/2024
0.0.1.2 686 7/8/2024
0.0.1.1 665 7/8/2024
0.0.1 672 7/7/2024 0.0.1 is deprecated because it has critical bugs.