Skip to content

Instantly share code, notes, and snippets.

@fffej
Created September 9, 2015 09:52
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 fffej/b4a48e86654bf8fef3d7 to your computer and use it in GitHub Desktop.
Save fffej/b4a48e86654bf8fef3d7 to your computer and use it in GitHub Desktop.
// I was just browsing the code, and there's a lot of this repetition.
if (!options.AreAllEnabled(Options.IgnoreKeys))
{
foreach (var val in ForeignKeys.CompareWith(target.ForeignKeys, options))
{
yield return val.AddContext(this);
}
}
if (!options.AreAllEnabled(Options.IgnoreChecks))
{
foreach (var val in CheckConstraints.CompareWith(target.CheckConstraints, options))
{
yield return val.AddContext(this);
}
}
// Is there a way to simplify this dramatically?
// Firstly, push the outer most if statement into the inner "CompareWith" so that the options check isn't done there
// Secondly, slap a select to add the context
// Finally, whack it all together with a giant concat statement.
return CheckConstraints.CompareWith(target.CheckConstraints, options).Select(x => x.AddContext(this)).Concat(
ForeignKeys.CompareWith(target.ForeignKeys, options).Select(x => x.AddContext(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment