Last active
August 8, 2018 17:37
-
-
Save alexbrillant/d5da473e904b0619469877cd36921bb6 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
public class ValidatedObservable : ObservableBase<string> { } | |
public abstract class Validation | |
{ | |
private readonly ValidatedObservable _validatedObservable; | |
private readonly bool _validated; | |
private readonly string _id; | |
private readonly ISet<string> _mustBeValidated; | |
protected Validation(ValidatedObservable validatedObservable, ISet<string> mustBeValidated, bool validated, string id) | |
{ | |
_validatedObservable = validatedObservable; | |
_mustBeValidated = mustBeValidated; | |
_validated = validated; | |
_id = id; | |
} | |
public void Execute() | |
{ | |
if (_mustBeValidated.Count != 0) | |
{ | |
return; | |
} | |
if (Validate()) | |
{ | |
_validated = true; | |
_validatedObservable.OnNext(_id); | |
} | |
} | |
public abstract bool Validate(); | |
public void OnValidated(string id) | |
{ | |
_mustBeValidated.Remove(id); | |
if (!_validated) { | |
Execute(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment