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

Accept nullable values in validation methods #17358

Conversation

sephit
Copy link
Contributor

@sephit sephit commented Aug 12, 2023

Description

Resolves #17357

This PR modifies the parameters of the following methods as nullable values. This ensure that anyone can validate if a variable is null or not.

    [ContractAnnotation("value:null => halt")]
    public static T NotNull<T>(T value, T? value, [InvokerParameterName][NotNull] string parameterName)
    [ContractAnnotation("value:null => halt")]
    public static T NotNull<T>(T value, T? value, [InvokerParameterName][NotNull] string parameterName, string message) 
    [ContractAnnotation("value:null => halt")]
    public static string NotNull(string value, string? value, [InvokerParameterName][NotNull] string parameterName, int maxLength = int.MaxValue, int minLength = 0)
    [ContractAnnotation("value:null => halt")]
    public static ICollection<T> NotNullOrEmpty<T>(ICollection<T>? value, [InvokerParameterName][NotNull] string parameterName)
    public static T NotDefaultOrNull<T>(
        T? value,
        [InvokerParameterName][NotNull] string parameterName)
        where T : struct

Checklist

  • I fully tested it as developer / designer and created unit / integration tests
  • I documented it (or no need to document or I will create a separate documentation issue)

How to test it?

            string? value = null;
            Check.NotNullOrWhiteSpace(value, "value");

@CLAassistant
Copy link

CLAassistant commented Aug 12, 2023

CLA assistant check
All committers have signed the CLA.

@maliming maliming requested review from maliming and realLiangshiwei and removed request for maliming August 12, 2023 08:07
@realLiangshiwei
Copy link
Member

Thanks @sephit

@realLiangshiwei realLiangshiwei added this to the 7.4-preview milestone Aug 15, 2023
@realLiangshiwei realLiangshiwei merged commit 0a6cef2 into abpframework:dev Aug 15, 2023
1 check passed
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.

Check.NotNullOrEmpty AND Check.NotNullOrWhiteSpace not accepting nullable string
3 participants