NIbaaa.DataCleaning
1.0.0
dotnet add package NIbaaa.DataCleaning --version 1.0.0
NuGet\Install-Package NIbaaa.DataCleaning -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="NIbaaa.DataCleaning" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NIbaaa.DataCleaning" Version="1.0.0" />
<PackageReference Include="NIbaaa.DataCleaning" />
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 NIbaaa.DataCleaning --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NIbaaa.DataCleaning, 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 NIbaaa.DataCleaning@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=NIbaaa.DataCleaning&version=1.0.0
#tool nuget:?package=NIbaaa.DataCleaning&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
using System; using System.Collections.Generic;
namespace DataCleaning.Entity { class Program { static void Main(string[] args) { // 创建清洗器 var cleaner = new EntityCleaner();
// ========== 配置清洗规则 ==========
var cleanRules = new List<FieldCleanConfig>
{
new FieldCleanConfig
{
FieldName = "StudentName",
RuleType = CleanRuleType.Trim,
IsRequired = true,
ErrorMessage = "学生姓名不能为空"
},
new FieldCleanConfig
{
FieldName = "StudentNo",
RuleType = CleanRuleType.Trim,
IsRequired = true
},
new FieldCleanConfig
{
FieldName = "PhoneNumber",
RuleType = CleanRuleType.FormatPhone,
DefaultValue = null
},
new FieldCleanConfig
{
FieldName = "Email",
RuleType = CleanRuleType.FormatEmail,
DefaultValue = null
},
new FieldCleanConfig
{
FieldName = "Age",
RuleType = CleanRuleType.RangeCheck,
MinValue = 0,
MaxValue = 120,
DefaultValue = 0
},
new FieldCleanConfig
{
FieldName = "Address",
RuleType = CleanRuleType.RemoveSpecialChars
},
new FieldCleanConfig
{
FieldName = "ClassName",
RuleType = CleanRuleType.Trim,
IsRequired = true,
DefaultValue = "默认班级"
}
};
cleaner.ConfigureCleanRules(cleanRules);
// ========== 配置匿名化规则 ==========
var anonymizeRules = new List<FieldAnonymizeConfig>
{
new FieldAnonymizeConfig
{
FieldName = "StudentName",
Type = AnonymizeType.Pseudonymize,
IsSensitive = true
},
new FieldAnonymizeConfig
{
FieldName = "PhoneNumber",
Type = AnonymizeType.Mask,
MaskPattern = "****",
MaskStart = 3,
MaskEnd = 4
},
new FieldAnonymizeConfig
{
FieldName = "IdCard",
Type = AnonymizeType.Mask,
MaskPattern = "********"
},
new FieldAnonymizeConfig
{
FieldName = "Email",
Type = AnonymizeType.Hash,
Salt = "student_salt"
},
new FieldAnonymizeConfig
{
FieldName = "Age",
Type = AnonymizeType.Generalization,
GeneralizationInterval = 10
},
new FieldAnonymizeConfig
{
FieldName = "BirthDate",
Type = AnonymizeType.DateOffset,
DateOffsetDays = 30
},
new FieldAnonymizeConfig
{
FieldName = "Score",
Type = AnonymizeType.Perturbation,
PerturbationRate = 0.05
}
};
cleaner.ConfigureAnonymizeRules(anonymizeRules);
// ========== 测试数据 ==========
var student = new StudentEntity
{
Id = 1,
StudentName = " 张三 ",
StudentNo = "2021001",
PhoneNumber = "13812345678",
Email = "zhangsan@qq.com",
Age = 20,
Address = "北京市朝阳区建国路88号",
ClassName = "计算机1班",
BirthDate = new DateTime(1990, 3, 7),
IdCard = "11010119900307663X",
Score = 85.5m
};
Console.WriteLine("========== 原始数据 ==========");
PrintStudent(student);
// ========== 只清洗 ==========
var cleanResult = cleaner.Clean(student);
Console.WriteLine("\n========== 清洗结果 ==========");
Console.WriteLine($"成功: {cleanResult.Success}");
Console.WriteLine($"清洗字段: {string.Join(", ", cleanResult.CleanedFields)}");
PrintStudent(student);
// ========== 清洗+匿名化 ==========
var student2 = new StudentEntity
{
Id = 2,
StudentName = " 李四 ",
StudentNo = "2021002",
PhoneNumber = "13912345678",
Email = "lisi@test.com",
Age = 25,
Address = "上海市浦东新区",
ClassName = "计算机2班",
BirthDate = new DateTime(1995, 5, 10),
IdCard = "31010119950510123X",
Score = 92.0m
};
var fullResult = cleaner.CleanAndAnonymize(student2, student2.Id.ToString());
Console.WriteLine("\n========== 清洗+匿名化结果 ==========");
Console.WriteLine($"成功: {fullResult.Success}");
Console.WriteLine($"清洗字段: {string.Join(", ", fullResult.CleanedFields)}");
Console.WriteLine($"匿名化字段: {string.Join(", ", fullResult.AnonymizedFields)}");
PrintStudent(student2);
}
static void PrintStudent(StudentEntity student)
{
Console.WriteLine($"ID: {student.Id}");
Console.WriteLine($"姓名: {student.StudentName}");
Console.WriteLine($"学号: {student.StudentNo}");
Console.WriteLine($"手机: {student.PhoneNumber}");
Console.WriteLine($"邮箱: {student.Email}");
Console.WriteLine($"年龄: {student.Age}");
Console.WriteLine($"地址: {student.Address}");
Console.WriteLine($"班级: {student.ClassName}");
Console.WriteLine($"生日: {student.BirthDate:yyyy-MM-dd}");
Console.WriteLine($"身份证: {student.IdCard}");
Console.WriteLine($"分数: {student.Score}");
}
}
}
| 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
- 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 | 92 | 5/11/2026 |