Skip to content
Discussion options

You must be logged in to vote

Well, the original example could just be defined as:

void AssertNotNull([NotNull] string? variableToTest)
{
    // will throw if variableToTest is null
}

This would provide exactly the semantics you want.

The second example, though, I'm not sure is possible. You'd need to have the results of a second method somehow passing through inference to the parameter of the first method, and I'm not really sure there's a way to do this. Maybe a particularly specialized attribute could do this, but I don't know how that could be generally-applicable enough to be worth adding to the language.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@johnknoop
Comment options

Answer selected by johnknoop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants