Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
NHail.ComponentModel.DataAnnotations.Fluent/ObjectValidations.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (39 sloc)
1.42 KB
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 System; | |
using System.Collections.Generic; | |
using System.ComponentModel.DataAnnotations; | |
using System.Linq; | |
using System.Security; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace NHail.ComponentModel.DataAnnotations.Fluent | |
{ | |
public class ObjectValidations<TSource> : IObjectValidations<TSource> | |
{ | |
private readonly IAttributeConfiguration<TSource> _provider; | |
public ObjectValidations(IAttributeConfiguration<TSource> provider) | |
{ | |
if (provider == null) | |
{ | |
throw new ArgumentNullException(nameof(provider)); | |
} | |
_provider = provider; | |
} | |
public IObjectValidations<TSource> Add<TValidationAttribute>(TValidationAttribute validationAttribute, | |
Action<TValidationAttribute> setter = null) | |
where TValidationAttribute : ValidationAttribute | |
{ | |
if (validationAttribute == null) | |
{ | |
throw new ArgumentNullException(nameof(validationAttribute)); | |
} | |
setter?.Invoke(validationAttribute); | |
_provider.AddAttributes(validationAttribute); | |
return this; | |
} | |
public IObjectValidations<TSource> Add<TValidationAttribute>(Action<TValidationAttribute> setter = null) | |
where TValidationAttribute : ValidationAttribute, new() | |
{ | |
return Add(new TValidationAttribute(), setter); | |
} | |
} | |
} |