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

[BUG] readme says to use ValidationRule on ReactiveValidationObject but it doesn't exist #433

Closed
trampster opened this issue Mar 26, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@trampster
Copy link

Describe the bug
The readme says has tells you that for INotifyDataErrorInfo you can inherit ReactiveValidationObject and call this.ValidationRule to add validation rules.

However ReactiveValidationObject doesn't have a ValidationRule method and so the example does not compile:

It can be seen from https://github.com/reactiveui/ReactiveUI.Validation/blob/main/src/ReactiveUI.Validation/Helpers/ReactiveValidationObject.cs which doesn't have a method called ValidationRule

public class SampleViewModel : ReactiveValidationObject
{
    public SampleViewModel()
    {
        // this line from the readme doesn't compile because ValidationRule doesn't exist.
        this.ValidationRule(
            viewModel => viewModel.Name, 
            name => !string.IsNullOrWhiteSpace(name),
            "Name shouldn't be null or white space.");
    }

    private string _name = string.Empty;
    public string Name
    {
        get => _name;
        set => this.RaiseAndSetIfChanged(ref _name, value);
    }
}

Steps To Reproduce
Us the sample from the readme
-> notice it doesn't compile because it uses a method that doesn't exist.

Expected behavior
I should be able to follow the readme and have a working validation example

Environment

  • OS: ubuntu 20.04
  • Device: Linux desktiop
  • Version: 2.2.1
  • UI toolkit: Avalonia
@trampster trampster added the bug Something isn't working label Mar 26, 2022
@glennawatson
Copy link
Collaborator

public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(

@glennawatson
Copy link
Collaborator

It exists as a extension method so make sure you include the correct namespaces

@trampster
Copy link
Author

Oh, thanks.
The problem with extension methods is that they look like normal methods and are completely undiscoverable, (ctrl . reactoring doesn't find it) So you have to just know that it's an extension method, and you have to just know what namespace it's in.

I think it would be helpful if the example in the readme example included the using statement. This would go a long way to helping with the on boarding experience for new users.

I would also suggest rethinking using extension methods like this as it will trip up a lot of new users.

@glennawatson
Copy link
Collaborator

Good idea in regards to the readme.

Extension methods are used pretty extensively throughout the entire ReactiveUI suite. Visual Studio 2022 has become a lot better at picking up when you should use an extension method these days.

Reason for the extension method it allows you to provide your own object types to validate against since not everyone will want to use the ReactiveValidationObject class.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants