-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored validation part #152
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Valit.Exceptions; | ||
using Valit.Result; | ||
|
||
namespace Valit.Rules | ||
{ | ||
internal static class ValitRuleExtensions | ||
{ | ||
internal static IValitResult ValidateRules<TObject>(this IEnumerable<IValitRule<TObject>> rules, IValitStrategy strategy, TObject @object) where TObject : class | ||
{ | ||
rules.ThrowIfNull(); | ||
|
||
var result = ValitResult.Success; | ||
|
||
foreach(var rule in rules.ToList()) | ||
{ | ||
result &= rule.Validate(@object); | ||
|
||
if(!result.Succeeded) | ||
{ | ||
strategy.Fail(rule, result, out bool cancel); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I said this a couple of days ago, but maybe lets make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arekbal did this as an out param. I think he's the right person to ask why we actualy use it :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleaner API when implementing that method. Instead of guessing or going through some docs to find why method returns bool and what it means(true for cancel or continue?), one just implements a method with clear declaration. |
||
if(cancel) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
|
||
strategy.Done(result); | ||
|
||
return result; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an
enum
to me, maybe it would be clearer to donew ValitResult()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can always hover on
var
so it's clear that'sIValitStrategy
object :DThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True 😄