Skip to content

Instantly share code, notes, and snippets.

@CoditCompany
Created June 28, 2019 12:17
Show Gist options
  • Save CoditCompany/267c05ba949b02e7e77ec23c2c181222 to your computer and use it in GitHub Desktop.
Save CoditCompany/267c05ba949b02e7e77ec23c2c181222 to your computer and use it in GitHub Desktop.
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