Last active
December 7, 2016 11:09
-
-
Save jackawatts/1369ce131f695996f385f87fde047500 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 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