Dado.ComponentModel.Mutations
0.5.1
Provides attributes that are used to help ensure data integrity for objects used as data sources.
Install-Package Dado.ComponentModel.Mutations -Version 0.5.1
dotnet add package Dado.ComponentModel.Mutations --version 0.5.1
<PackageReference Include="Dado.ComponentModel.Mutations" Version="0.5.1" />
paket add Dado.ComponentModel.Mutations --version 0.5.1
#r "nuget: Dado.ComponentModel.Mutations, 0.5.1"
// Install Dado.ComponentModel.Mutations as a Cake Addin
#addin nuget:?package=Dado.ComponentModel.Mutations&version=0.5.1
// Install Dado.ComponentModel.Mutations as a Cake Tool
#tool nuget:?package=Dado.ComponentModel.Mutations&version=0.5.1
Sample Usage
The following class shows that a property should be converted to lowercase and replaced of invalid characters.
using System.Text.RegularExpressions;
public class User
{
private string _userName;
public string UserName {
get {
return _userName;
}
set {
value = value.ToLower();
_userName = Regex.Replace(value, @"[^a-z0-9._]", String.Empty);
}
}
}
Altering the example to use a mutation attributes will produce the following code.
using Dado.ComponentModel.DataMutations;
public class User
{
[
ToLower,
RegexReplace(@"[^a-z0-9._]")
]
public string UserName { get; set; }
}
Now, when Mutator.Mutate(context);
is executed the value of User.UserName
will be lowercased and have all invalid characters replaced.
Sample Usage
The following class shows that a property should be converted to lowercase and replaced of invalid characters.
using System.Text.RegularExpressions;
public class User
{
private string _userName;
public string UserName {
get {
return _userName;
}
set {
value = value.ToLower();
_userName = Regex.Replace(value, @"[^a-z0-9._]", String.Empty);
}
}
}
Altering the example to use a mutation attributes will produce the following code.
using Dado.ComponentModel.DataMutations;
public class User
{
[
ToLower,
RegexReplace(@"[^a-z0-9._]")
]
public string UserName { get; set; }
}
Now, when Mutator.Mutate(context);
is executed the value of User.UserName
will be lowercased and have all invalid characters replaced.
Dependencies
-
.NETFramework 4.6.1
- System.ComponentModel.Annotations (>= 4.1.0)
-
.NETStandard 1.4
- NETStandard.Library (>= 1.6.1)
- System.ComponentModel (>= 4.0.1)
- System.ComponentModel.Annotations (>= 4.1.0)
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 4.1.0)
Used By
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.