Jasmine.Extensions
1.0.0
dotnet add package Jasmine.Extensions --version 1.0.0
NuGet\Install-Package Jasmine.Extensions -Version 1.0.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="Jasmine.Extensions" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Jasmine.Extensions" Version="1.0.0" />
<PackageReference Include="Jasmine.Extensions" />
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 Jasmine.Extensions --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Jasmine.Extensions, 1.0.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.
#:package Jasmine.Extensions@1.0.0
#: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=Jasmine.Extensions&version=1.0.0
#tool nuget:?package=Jasmine.Extensions&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Jasmine.Extensions
Jasmine.Extensions 是一组用于 .NET 的轻量级扩展方法集合,包含对数值(decimal/double/float)、字符串、集合(List)与 DataTable 互转等常用功能的扩展,便于在项目中复用常见工具方法。
特性
- 精确的四舍五入(向远离零方向的舍入)扩展:
decimal,double,float的ToFixed方法 - 常用字符串安全转换:
ToInt、ToLong、ToDecimal、ToDouble、ToFloat、ToBool、ToGuid、ToDateTime等 - 字符串判空简写:
IsNullOrEmpty、IsNullOrWhiteSpace(对输入会先做 Trim) - List 辅助:
AddRangeIfNotExists(仅添加不存在的元素)、ToDataTable(将对象列表转换为DataTable) - DataTable 辅助:
ToList<T>(把 DataTable 的行映射回对象列表)
安装
当前包在项目内以 Jasmine.Extensions 打包,示例版本见 bin/Debug(例如 Jasmine.Extensions.1.0.0.nupkg)。使用 NuGet 安装:
dotnet add package Jasmine.Extensions --version 1.0.0
(如果你本地已产生 nupkg,也可以使用 dotnet nuget add source / 本地源或直接引用项目来调试)
名称空间
各扩展按功能划分到不同名称空间:
Jasmine.Extensions.Decimals—decimal扩展Jasmine.Extensions.Doubles—double扩展Jasmine.Extensions.Floats—float扩展Jasmine.Extensions.Strings— 字符串扩展Jasmine.Extensions.Lists— List / DataTable 扩展Jasmine.Extensions.Tables— DataTable → List<T>
示例:在文件顶部添加 using Jasmine.Extensions.Strings; 即可使用字符串扩展方法。
快速示例
下面均为 C# 示例,演示常见用法。
数值舍入(ToFixed)
using Jasmine.Extensions.Decimals;
using Jasmine.Extensions.Doubles;
using Jasmine.Extensions.Floats;
decimal d = 1.2345m;
var dFixed = d.ToFixed(2); // 1.23 (向远离零舍入)
double x = 2.3456;
var xFixed = x.ToFixed(3);
float f = 3.14159f;
var fFixed = f.ToFixed(2);
List 操作
using Jasmine.Extensions.Lists;
var list = new List<int> { 1, 2 };
list.AddRangeIfNotExists(new[] { 2, 3, 4 }); // 只添加 3 和 4
// 将对象列表转换为 DataTable
var people = new List<Person> { new Person { Id = 1, Name = "Alice" } };
var table = people.ToDataTable();
DataTable → List<T>
using Jasmine.Extensions.Tables;
using System.Data;
DataTable table = /* 从其它来源获得 */ new DataTable();
// 假设 DataTable 的列与类型与 Person 的属性匹配
var list = table.ToList<Person>();
字符串转换与判空
using Jasmine.Extensions.Strings;
string s = "2023-10-27T12:34:56Z";
var dt = s.ToDateTime(); // 解析若失败返回 DateTime.UtcNow
string guidStr = "d2719f2b-...";
var guid = guidStr.ToGuid(); // 解析失败返回 Guid.Empty
string num = "123";
int i = num.ToInt(); // 123
bool b = "true".ToBool(); // true
string empty = " ";
var isEmpty = empty.IsNullOrWhiteSpace(); // true
API 摘要(常用方法)
- DecimalExtension
- decimal ToFixed(this decimal value, int decimals)
- DoubleExtension
- double ToFixed(this double value, int digits)
- FloatExtension
- float ToFixed(this float value, int digits)
- ListExtension
- void AddRangeIfNotExists<T>(this List<T> list, IEnumerable<T> items)
- DataTable ToDataTable<T>(this List<T> items)
- StringExtension
- bool IsNullOrEmpty(this string value)
- bool IsNullOrWhiteSpace(this string value)
- DateTime ToDateTime(this string value, string format = "")
- DateTimeOffset ToDateTimeOffset(this string value)
- Guid ToGuid(this string value)
- bool ToBool(this string value)
- int ToInt(this string value)
- long ToLong(this string value)
- decimal ToDecimal(this string value)
- double ToDouble(this string value)
- float ToFloat(this string value)
- TableExtension
- List<T> ToList<T>(this DataTable table)
请参考各目录下的源文件以获取更详细的 XML 注释与边界条件说明。
贡献与联络
欢迎提 issue 或 PR。建议流程:
- 新增 issue 描述需求或 bug。
- 新建分支并提交小而明确的修改。
- 提交 PR 并说明变更目的与测试方式。
许可
本项目包含 LICENSE 文件,请查看仓库根目录的 LICENSE。
| Product | Versions 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. 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.
-
.NETStandard 2.0
- No dependencies.
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 |
|---|---|---|
| 1.0.0 | 241 | 10/27/2025 |