Created
June 28, 2019 12:17
-
-
Save CoditCompany/267c05ba949b02e7e77ec23c2c181222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FPrimitive; | |
public class ProductName | |
{ | |
private readonly string _value; | |
/// Prevents a default instance of the type from being created. | |
private ProductName(string value) | |
{ | |
_value = value; | |
} | |
/// Creates a product name instance based on untrusted data. | |
public static ValidationResult<ProductName> Create(string untrusted) | |
{ | |
return Spec.Of<string>() | |
.NotNull("Product name should not be 'null'") | |
.NotEmpty("Product name should not be empty") | |
.NotWhiteSpace("Product name should not contain only white-space characters") | |
.Regex("^[a-zA-Z ]+$", "Product name should only contain characters from a-z") | |
.CreateModel(untrusted, validated => new ProductName(validated)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment