Jeff.Tool
1.0.4
dotnet add package Jeff.Tool --version 1.0.4
NuGet\Install-Package Jeff.Tool -Version 1.0.4
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="Jeff.Tool" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Jeff.Tool" Version="1.0.4" />
<PackageReference Include="Jeff.Tool" />
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 Jeff.Tool --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Jeff.Tool, 1.0.4"
#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 Jeff.Tool@1.0.4
#: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=Jeff.Tool&version=1.0.4
#tool nuget:?package=Jeff.Tool&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
.NET 常用工具类库
依赖注入
- 服务注册
注册泛型接口的所有实现类,IServiceCollection.AddClasses<T>()// 默认注册为单独的类服务,生命周期为 Scoped,扫描入口程序集及其引用 builder.Services.AddClasses<IMyService>(); MyService s = app.Services.GetRequiredService<MyService>(); // 注册为接口服务,以类名为键 builder.Services.AddClasses<IMyService>(opt => opt .FromAssembly(Assembly.Load("BLL.dll")) // 默认为 FromEntryAssemblyDependencies() .AsImplementedInterface() // 默认是 AsClassSelf() .WithTransient()); // 默认是 WithScoped() IMyService s = app.Services.GetRequiredKeyedService<IMyService>(typeof(MyService).FullName);
参数验证
用于验证方法参数和实体属性的有效性。
- 密码验证
密码复杂度验证。通过直接指定或配置文件,配置复杂度。
配置文件示例:public class User { // 默认复杂度为长度6~20位,同时包含小写字母和数字 [Password] public string Password_1 { get; set; } // 通过配置文件配置复杂度 [Password("Auth:PasswordComplexity")] public string Password_2 { get; set; } // 指定密码复杂度,6~20位,包含小写字母和数字 [Password(PasswordComplexity.RequireDigit | PasswordComplexity.RequireLowercase, 6, 20)] public string Password_3 { get; set; } }"Auth": { "PasswordComplexity": { "MinLength": 6, // 密码最小长度 "MaxLength": 20, // 密码最大长度 "RequireDigit": true, // 是否需要数字 "RequireLowercase": true, // 是否需要小写字母 "RequireUppercase": false, // 是否需要大写字母 "RequireNonAlphanumeric": false // 是否需要非字母数字字符 } } - 11位手机号验证
验证中国大陆的11位手机号。public class User { [Phone_CN] public string Phone { get; set; } }
枚举
- 扩展方法
Enum.GetAttr<TAttribute>()
获取枚举指定特性的值,比如 [Message]string? message = HttpMethodEnum.Attr<MessageAttribute>()?.Message;
表达式
- 属性表达式
ExpressionTool.CreatePropertyLambda<User>("UserName"); // u => u.UserName ExpressionTool.CreatePropertyLambda<User, string>("UserName"); // u => u.UserName - 比较表达式
ExpressionTool.CreateEqualLambda<User>("UserName", "Tom"); // u => u.UserName == "Tom" ExpressionTool.CreateNotEqualLambda<User>("UserName", "Tom"); // u => u.UserName != "Tom" ExpressionTool.CreateGreaterThanLambda<User>("Age", 10); // u => u.Age > 10 ExpressionTool.CreateGreaterThanOrEqualLambda<User>("Age", 10); // u => u.Age >= 10 ExpressionTool.CreateLessThanLambda<User>("Age", 10); // u => u.Age < 10 ExpressionTool.CreateLessThanLambdaOrEqualLambda<User>("Age", 10); // u => u.Age <= 10 ExpressionTool.CreateEqualDefaultLambda<User>("Age"); // u => u.Age == 0 || u.Age == null - 逻辑表达式
ExpressionTool.CreateAndAlsoLambda<User>( // u => u.UserName == "Tom" && u.Age > 10 ExpressionTool.CreateEqualLambda<User>("UserName", "Tom").Body, ExpressionTool.CreateGreaterThanLambda<User>("Age", 10).Body ); ExpressionTool.CreateOrElseLambda<User>( // u => u.UserName == "Tom" || u.Age > 10 ExpressionTool.CreateEqualLambda<User>("UserName", "Tom").Body, ExpressionTool.CreateGreaterThanLambda<User>("Age", 10).Body );
其他
待补充
| Product | Versions 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
- Microsoft.AspNetCore.StaticFiles (>= 2.3.0)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.