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

Fix for Stefan's category/classification issue in WithNotifications #834

Merged

Conversation

RichardIrons-neo4j
Copy link
Contributor

This is a fix for this issue Stefano raised.

At present, there are two overloads for the WithNotifications method on both the ConfigBuilder and SessionConfigBuilder:

// originally present
public ConfigBuilder WithNotifications(Severity? minimumSeverity, Category[] disabledCategories)

// added with the GQL Notifications work (which is in preview)
public ConfigBuilder WithNotifications(Severity? minimumSeverity, Classification[] disabledClassifications)

However, by adding the second overload, the following code will no longer compile:

builder.WithNotifications(Severity.Warning, null);

with the compiler giving the following error:

error CS0121: The call is ambiguous between the following methods or properties:
'ConfigBuilder.WithNotifications(Severity?, Category[])' and
'ConfigBuilder.WithNotifications(Severity?, Classification[])'

To solve the problem we can move or change the second overload since it is preview but code calling the first overload in whatever manner must compile with no changes.

The solution I went with was to combine both methods into a single overload with the following signature:

public ConfigBuilder WithNotifications(
        Severity? minimumSeverity,
        Category[] disabledCategories = null,
        Classification[] disabledClassifications = null)

This can be used as follows:

// same behaviour as before
.WithNotifications(Severity.Warning);

// same behaviour as before, although the IDE will point out that the
// second parameter is not required
.WithNotifications(Severity.Warning, null);

// same behaviour as before
.WithNotifications(Severity.Warning, [Category.Hint, Category.Unsupported]);

// also allowed, identical to previous line
.WithNotifications(
    Severity.Warning, 
    disabledCategories: [Category.Hint, Category.Unsupported]);

// to disable by classification
.WithNotifications(
    Severity.Warning, 
    disabledClassifications: [Classification.Hint, Classification.Unsupported]);

// or
.WithNotifications(
    Severity.Warning, 
    null,
    [Classification.Hint, Classification.Unsupported]);

// you can even do this
.WithNotifications(
    Severity.Warning, 
    [Category.Performance, Category.Topology],
    [Classification.Hint, Classification.Unsupported]);

In the last example, all four of the specified exclusions will apply.

I added a test that initially failed to compile, by passing null as the second parameter, and that test now works fine.

I also did some minor tidying re XML docs etc, and moved GQL Notifications out of preview.

Copy link
Contributor

@AndyHeap-NeoTech AndyHeap-NeoTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to be correct to me.

Copy link
Contributor

@stefano-ottolenghi stefano-ottolenghi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful 🤸

@RichardIrons-neo4j RichardIrons-neo4j merged commit 2dbd5db into neo4j:5.0 Jan 17, 2025
5 checks 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.

3 participants