Created
January 24, 2011 02:50
-
-
Save jmarnold/792742 to your computer and use it in GitHub Desktop.
Validation Rules in Fubu
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 interface IValidationQuery | |
{ | |
IEnumerable<IValidationRule> RulesFor(object target); | |
IEnumerable<IValidationRule> RulesFor(Type targetType); | |
T GetRule<T>(Accessor accessor) where T : class, IValidationRule; | |
T GetStrategy<T>(Accessor accessor) where T : class, IFieldValidationStrategy; | |
void ForRule<T>(Accessor accessor, Action<T, Accessor> action) where T : class, IValidationRule; | |
void ForStrategy<T>(Accessor accessor, Action<T, Accessor> action) where T : class, IFieldValidationStrategy; | |
bool HasRule<T>(Accessor accessor) where T : class, IValidationRule; | |
bool HasStrategy<T>(Accessor accessor) where T : class, IFieldValidationStrategy; | |
} |
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 interface IValidationRule | |
{ | |
bool AppliesTo(Accessor accessor); | |
void Validate(object target, Notification notification); | |
} |
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 interface IValidationSource | |
{ | |
IEnumerable<IValidationRule> RulesFor(Type type); | |
} |
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 MyCustomValidationRegistry : ValidationRegistry | |
{ | |
public MyCustomValidationRegistry() | |
{ | |
Rules | |
.If(accessor => accessor.Name.Contains("Email")) | |
.ApplyStrategy<MyCustomEmailStrategy>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment