Liwendong.Resources
2.0.1
dotnet add package Liwendong.Resources --version 2.0.1
NuGet\Install-Package Liwendong.Resources -Version 2.0.1
<PackageReference Include="Liwendong.Resources" Version="2.0.1" />
<PackageVersion Include="Liwendong.Resources" Version="2.0.1" />
<PackageReference Include="Liwendong.Resources" />
paket add Liwendong.Resources --version 2.0.1
#r "nuget: Liwendong.Resources, 2.0.1"
#:package Liwendong.Resources@2.0.1
#addin nuget:?package=Liwendong.Resources&version=2.0.1
#tool nuget:?package=Liwendong.Resources&version=2.0.1
Liwendong.Resources
静态资源集合:行政区划、汉字与拼音、MIME 类型、时间常量、常用提示语、证件号码规则、单位换算、HTTP 状态码。
零外部依赖,覆盖 net8.0 / netstandard2.1 / netstandard2.0 / net451 / net46。
安装
Install-Package Liwendong.Resources
dotnet add package Liwendong.Resources
内容一览
| 类型 | 说明 |
|---|---|
AreaResources |
中国行政区划三级数据(GB/T 2260)与查询 API |
ChineseCharacterResources |
GB2312 一级字、常用 2500/3500 字、百家姓、民族、拼音索引表 |
IOResources |
文件扩展名 ↔ Content-Type 双向映射与类型判定 |
TimeResources |
日期时间格式串、时长秒数 / TimeSpan、星期与月份名称 |
TipsResources |
常用业务提示语(全部为 const,可作默认参数值) |
IdentityResources |
身份证校验码规则、手机号 / 银行卡号规则 |
UnitResources |
存储 / 长度 / 质量 / 面积 / 体积 / 时间单位换算表 |
HttpStatusResources |
HTTP 状态码与 Reason Phrase |
用法示例
行政区划三级联动
foreach (AreaItem province in AreaResources.Provinces)
{
Console.WriteLine($"{province.Code} {province.Name}");
}
IReadOnlyList<AreaItem> cities = AreaResources.GetCities(130000); // 河北省下辖地市
IReadOnlyList<AreaItem> districts = AreaResources.GetDistricts(130100); // 石家庄下辖区县
AreaResources.GetFullName(130102); // "河北省 石家庄市 长安区"
AreaResources.GetDistricts(110000); // 直辖市会穿透「市辖区」直接返回真实区
AreaResources.GetName(440305); // "南山区"
AreaResources.FindByName("湖里区"); // 同名返回多条
数据出自民政部公布的 2024 年度县级以上行政区划代码:省级 34 项、地级 343 项、县级 3332 项。 台湾省、香港特别行政区、澳门特别行政区只有省级条目。 直辖市下的「市辖区 / 县」、部分省份的「省直辖县级行政区划」是 GB/T 2260 的汇总节点, 可用
AreaItem.IsSummaryNode识别。
MIME 类型
IOResources.GetContentType("report.PDF"); // application/pdf
IOResources.GetContentType("/wwwroot/a/b.PNG"); // image/png(路径、大小写、带不带点都行)
IOResources.GetContentType("http://x/y.mp4?t=1");// video/mp4(自动去掉查询串)
IOResources.GetContentType("zzz"); // application/octet-stream(兜底)
IOResources.GetExtensions("image/jpeg"); // 反查扩展名
IOResources.IsImage("a.svg"); // true
IOResources.IsArchive("a.7z"); // true
IOResources.IsFont("a.woff2"); // true
表内共 639 条映射,查询大小写不敏感。
汉字与拼音
ChineseCharacterResources.GetGB2312String(); // GB2312 一级汉字 3755 个
ChineseCharacterResources.GetChinese3500().Count; // 3500(V1 实际只有 161)
ChineseCharacterResources.GetChinese2500().Count; // 2500(V1 实际只有 28)
int code;
ChineseCharacterResources.TryGetGb2312Level1Code('啊', out code); // 45217 == 0xB0A1
ChineseCharacterResources.FirstNames; // 百家姓(已切分,不用每次 Split)
ChineseCharacterResources.NationNames; // 56 个民族
TryGetGb2312Level1Code提供的值为(高位字节 << 8 & 0xff00) + (低位字节 & 0xff), 可直接与FirstPinYinCodes/PinYinCodes配合做拼音检索。 之所以需要它:现代 .NET 已不内建 GB2312 编码表,Encoding.GetEncoding("GB2312")会抛异常。
其它
TimeResources.GetFullName3(); // 见下行
TimeResources.GetWeekdayName(DayOfWeek.Wednesday); // "星期三"
TipsResources.GetTip("SaveSuccess"); // "保存成功"
IdentityResources.GetIdCardCheckCode("11010519491231002"); // 'X'
IdentityResources.GetIdCardProvince("11010519491231002X"); // "北京市"
UnitResources.FormatBytes(1536); // "1.50 KB"
UnitResources.Convert(1, UnitResources.LengthUnits, "mi", "m"); // 1609.344
HttpStatusResources.GetReasonPhrase(404); // "Not Found"
V1 → V2 迁移说明
V2 修复了 V1 的若干缺陷并收敛了 API,这是一次破坏性升级(见下方逐一说明)。
1. 行为修正
| 项 | V1 | V2 |
|---|---|---|
GetGB2312String() |
低位字节误用区号,只返回 40 个不同字符 | 返回完整 3755 个一级汉字 |
GetChinese3500() |
实际 161 个字 | 3500 个字 |
GetChinese2500() |
实际 28 个字 | 2500 个字 |
GetGB2312String() 跨平台 |
.NET Core / 5+ 上抛 ArgumentException |
全平台可用(数据已固化) |
| MIME 取值 | .js 用了废弃的 application/x-javascript;.rar / .ttf / .ics 等是 application/octet-stream |
已更正,并补充 json / webp / avif / woff2 / wasm / apk / mkv / webm / md 等共计 73 条 |
CityNames |
313 条且被截断,含重复项、过时地名(莱芜市)与占位符「直辖县级」 | 343 条地级条目 + 3255 条县级条目,可按代码逐级查询 |
若此前依赖以上内容做过「随机中文名字.DBConn / 随机常用字」之类功能,升级后会明显变化 —— 这是修正而非回归。
2. 类型收敛为只读集合
公开的可变静态字段收敛成了只读集合,目的是避免外部代码改写共享数据。
放开不一定报错,多数是 数组.Length 与索引处需要调整:
| V1 | V2 | 需要的改动 |
|---|---|---|
PriceUnits / NumberUnits : string[] |
IReadOnlyList<string> |
.Length → .Count |
PinYins / PinYinCodes / FirstPinYinCodes : string[] / int[] |
IReadOnlyList<string> / IReadOnlyList<int> |
.Length → .Count |
PinYinAndChineseCharacter : string[][] |
IReadOnlyList<IReadOnlyList<string>> |
.Length → .Count |
GetChinese2500() / GetChinese3500() : HashSet<char> |
IReadOnlyCollection<char> |
只读返回(原先能改内部缓存,现在不能) |
FileExtensionToContentTypeMappings : IDictionary |
IReadOnlyDictionary(readonly) |
不再允许写入 |
TipsResources 的常量仍是 const string,可继续用作默认参数值。
3. 拼写修正(旧成员保留一个大版本)
旧(已标记 [Obsolete]) |
新 |
|---|---|
IOResoures(类名与文件名都是错的) |
IOResources |
ProvinceNamse |
ProvinceNames |
FristPinyinChineseCharacter |
FirstPinyinChineseCharacter |
这三个旧成员将在 V3.0 移除,请尽快替换。
更新日志
2.0.1 (2026-10-17)
- 修复:
UnitResources.Convert未知单位不再静默返回原值,改为抛出ArgumentException(方法名保持不变,XML 注释说明与System.Convert的区别:本方法是单位换算而非类型转换)。 - 修复:
TipsResources.FuctionNotOpen文案"尽情期待"更正为"敬请期待";XML 注释注明FuctionNotOpen(应为 FunctionNotOpen)与Faild系列(应为 Failed)的正确拼写,公共成员名保持不变。 - 优化:
TimeResources注释明确Seconds_Year_1 = 31536000为平年 365 天、Seconds_Month_1 = 2592000为 30 天近似值。
V2.0.0
- 修复:
GetGB2312String()低位字节误用区号,实际只产出 40 个不同汉字(下游 2500/3500 常用字只剩 28 / 161 个) - 修复:去掉对
Encoding.GetEncoding("GB2312")的依赖,该方法在 .NET Core / .NET 5 及以上直接抛异常 - 修复:
TargetFrameworks写成非标准的netstandard20 - 修复:
CityNames数据被截断且含重复 / 过时 / 非行政区条目 - 修复:
TimeResources.Seconds_Houre_8注释写成「4小时」(实为 8 小时) - 修复:
FirstPinyinChineseCharacter等缺少readonly,GetChinese2500/3500每次调用重建HashSet - 新增:目标框架
net8.0/netstandard2.1,net8.0下用FrozenDictionary优化查表 - 新增:行政区划三级数据(民政部 2024 年度,3709 条)与 9 个查询方法
- 新增:MIME 查询 API(
GetContentType/GetExtensions/IsImage等)+ 73 条现代类型 - 新增:
IdentityResources、UnitResources、HttpStatusResources - 新增:
TimeResources的 ISO8601 / RFC1123 格式串、TimeSpan常量、星期与月份名称 - 新增:
TipsResources扩充至 40+ 条并按场景分组 - 优化:公开成员统一收敛为只读集合;
FirstName/LastName/NationName增加已切分版本 - 工程:补齐包元数据、
IncludeSymbols(snupkg)、GenerateDocumentationFile;清理 TFS 时代残留
V1.1.0
- 新增区域资源
V1.0.5
- 调整时间转成秒针的资源信息
| 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 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. |
| .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 is compatible. |
| .NET Framework | net451 is compatible. net452 was computed. net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 is compatible. 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. |
-
.NETFramework 4.5.1
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Liwendong.Resources:
| Package | Downloads |
|---|---|
|
Liwendong.Utility
通用辅助工具集合 |
GitHub repositories
This package is not used by any popular GitHub repositories.