Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jackawatts/1369ce131f695996f385f87fde047500 to your computer and use it in GitHub Desktop.
Save jackawatts/1369ce131f695996f385f87fde047500 to your computer and use it in GitHub Desktop.
using Conventional;
using Conventional.Conventions;
using System;
using System.Linq;
namespace Conventions
{
public static class Convention
{
public static RequiresACorrespondingConcreteImplementationConventionSpecification InterfaceMustHaveCorrespondingConcreteType(Type[] subjects)
{
return new RequiresACorrespondingConcreteImplementationConventionSpecification(subjects);
}
}
public class RequiresACorrespondingConcreteImplementationConventionSpecification : ConventionSpecification
{
private readonly Type[] _subjects;
public RequiresACorrespondingConcreteImplementationConventionSpecification(Type[] subjects)
{
_subjects = subjects;
}
protected override string FailureMessage
{
get { return "Could not find required corresponding implementation of {0}"; }
}
public override ConventionResult IsSatisfiedBy(Type type)
{
if (_subjects.SelectMany(x => x.GetInterfaces()).Any(i => i == type))
{
return ConventionResult.Satisfied(type.FullName);
}
return ConventionResult.NotSatisfied(type.FullName, string.Format(FailureMessage, type.FullName));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment