Skip to content
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

change EnableNotifyError field to property #270

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zerodev1200
Copy link

I have created a library called R3Utility.
In this library, I have defined the following method:

public static Observable<bool> CreateCanExecuteSource(bool forceInitialNotification = true, params IBindableReactiveProperty[] properties)
{
    if (properties == null || properties.Length == 0)
    {
        throw new ArgumentNullException(nameof(properties));
    }
    // Create observables for HasErrors of each property
    var errorObservables = properties
                            .Select(prop =>
                            {
                                if (forceInitialNotification)
                                {
                                    prop.OnNext(prop.Value); // Force initial notification
                                }
                                return Observable.EveryValueChanged(prop, x => x.HasErrors);
                            });
    return errorObservables.CombineLatestValuesAreAllFalse();
}

By changing EnableNotifyError to a property, I can now perform the following validation:

if (!prop.EnableNotifyError)
{
    throw new ArgumentException($"Property must have EnableValidation() called.");
}

I placed bool EnableNotifyError { get; } in the non-generic interface rather than the generic one to ensure it can be accessed regardless of the type in the above method.

Please review this implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant