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" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dado.ComponentModel.Mutations --version 0.5.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

API Documentation

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.

API Documentation

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.5.1 939 9/21/2018
0.5.0 149 8/19/2018
0.4.0 389 4/13/2017