Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Created April 5, 2021 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyubuns/83080ab6dfa02207cbd60c8d261920d1 to your computer and use it in GitHub Desktop.
Save kyubuns/83080ab6dfa02207cbd60c8d261920d1 to your computer and use it in GitHub Desktop.
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