Created
January 6, 2011 21:29
-
-
Save KevM/768626 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class ModelMapSchemaValidationSource : IValidationSource | |
| { | |
| private readonly IContainer _container; | |
| private readonly SchemaValidationVisitor _schemaValidationVisitor; | |
| public ModelMapSchemaValidationSource(IContainer container, SchemaValidationVisitor schemaValidationVisitor) | |
| { | |
| _container = container; | |
| _schemaValidationVisitor = schemaValidationVisitor; | |
| } | |
| public IEnumerable<IValidationRule> RulesFor(Type type) | |
| { | |
| var modelMapGenericType = typeof (ModelMap<>).MakeGenericType(type); | |
| var modelMap = _container.TryGetInstance(modelMapGenericType); | |
| if (modelMap == null) return new IValidationRule[0]; | |
| modelMapGenericType.InvokeMember("Accept", BindingFlags.InvokeMethod |BindingFlags.Instance |BindingFlags.Public, null, modelMap, new[] {_schemaValidationVisitor}); | |
| return _schemaValidationVisitor.Rules; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment