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

Add NotDefault and ValidElements #65

Closed
scottdorman opened this issue Sep 30, 2020 · 2 comments · Fixed by #66
Closed

Add NotDefault and ValidElements #65

scottdorman opened this issue Sep 30, 2020 · 2 comments · Fixed by #66

Comments

@scottdorman
Copy link
Contributor

It would be nice to have a convenience method on Requires which easily allows validating a collection against a predicate. This method could look similar to:

[DebuggerStepThrough]
public static void ValidElements<T>([ValidatedNotNull] IEnumerable<T>? values, Predicate<T> predicate, string parameterName, string message)
{
    if (predicate is null)
    {
        throw new ArgumentNullException(nameof(predicate));
    }

    if (values is object)
    {
        foreach (T value in values)
        {
            if (!predicate(value))
            {
                throw new ArgumentException(message, parameterName);
            }
        }
    }
}

This could then be used like

public void SetFieldWidths(params int[] fieldWidths)
{
    Requires.NotNullOrEmpty(fieldWidths, nameof(fieldWidths));
    Requires.ValidElements(fieldWidths.SkipLast(1), fw => fw >= 0, "All width's except the last must be greater than 0", nameof(fieldWidths));
}

Similarly, adding a Requires.NotDefault<T> for enums.

scottdorman added a commit to scottdorman/vs-validation that referenced this issue Sep 30, 2020
@scottdorman
Copy link
Contributor Author

What's the process for the translations on string resources? Should I translate them myself using something like Bing translate?

AArnott pushed a commit that referenced this issue Oct 2, 2020
* Adds NotDefault and ValidElements methods.

Closes #65.

* Missed the resource file changes.

* Fixing SA1513/SA1516.
@AArnott
Copy link
Member

AArnott commented Oct 2, 2020

We have a loc team that provides translations.

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 a pull request may close this issue.

2 participants