Created
April 5, 2021 02:07
-
-
Save kyubuns/83080ab6dfa02207cbd60c8d261920d1 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 System; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using MasterMemory.Validation; | |
namespace Sandbox | |
{ | |
public static class ValidatorExtension | |
{ | |
public static void Single<TElement>(this ValidatableSet<TElement> self, Expression<Func<TElement, bool>> predicate) | |
{ | |
var f = predicate.Compile(true); | |
var count = self.TableData.Count(a => f(a)); | |
if (count != 1) | |
{ | |
throw new Exception($"Unique failed ({count} items): {predicate.ToSpaceBodyString()}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment