Skip to content

Instantly share code, notes, and snippets.

@alexbrillant
Last active August 8, 2018 17:37
Show Gist options
  • Save alexbrillant/d5da473e904b0619469877cd36921bb6 to your computer and use it in GitHub Desktop.
Save alexbrillant/d5da473e904b0619469877cd36921bb6 to your computer and use it in GitHub Desktop.
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