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

[AzureMonitorExporter] fix more nullables with NotNullWhenAttribute #33966

Merged
merged 1 commit into from
Feb 8, 2023

Conversation

TimothyMothra
Copy link
Contributor

@TimothyMothra TimothyMothra commented Feb 7, 2023

Towards #34013

This is a follow up to #33870.
In that PR, I had to use the Null-Forgiving operator (!) to declare that the out parameter of a TryGet method was not null.

The better way to do this is to use a null-state attribute.

Changes

How to use:

Assume you write the following method:

public bool TryParse(string number, out int? value)

The compiler is not aware that value is not null and gives an error.

Instead you can write:

public bool TryParse(string number, [NotNullWhen(true)] out int? value)

Which indicates that when this method returns true, the value of value is not null.

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

@TimothyMothra TimothyMothra merged commit 95de9f7 into main Feb 8, 2023
@TimothyMothra TimothyMothra deleted the tilee/nullable4 branch February 8, 2023 00:19
@TimothyMothra TimothyMothra changed the title [AzureMonitorExporter] fix more nullables [AzureMonitorExporter] fix more nullables with NotNullWhenAttribute Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Monitor - Exporter Monitor OpenTelemetry Exporter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants