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

Make a way to suppress MA0003 #3

Merged
merged 1 commit into from
Aug 10, 2023
Merged

Make a way to suppress MA0003 #3

merged 1 commit into from
Aug 10, 2023

Conversation

jonathanpeppers
Copy link
Owner

I add a test to allow:

new UITextField().EditingDidBegin += _proxy.OnEditingDidBegin;

// This should warn, because it is NSObject
class UITextFieldProxy : NSObject
{
    // But then we suppressed the warning
    [UnconditionalSuppressMessage("Memory", "MA0003")]
    public void OnEditingDidBegin(object sender, EventArgs e) { }
}

I added code to look up the attribute on the method from this statement:

new UITextField().EditingDidBegin += _proxy.OnEditingDidBegin;

This also uncovered a bug in the analyzer:

--if (attribute.AttributeClass.ContainingNamespace.Name != "System.Diagnostics.CodeAnalysis")
++if (attribute.AttributeClass.ContainingNamespace.ToString() != "System.Diagnostics.CodeAnalysis")

In this example Name was just "CodeAnalysis". I have no idea why, but using .ToString() instead was successful. All tests pass with this change, so I'm going with it.

I add a test to allow:

    new UITextField().EditingDidBegin += _proxy.OnEditingDidBegin;

    // This should warn, because it is NSObject
    class UITextFieldProxy : NSObject
    {
        // But then we suppressed the warning
        [UnconditionalSuppressMessage("Memory", "MA0003")]
        public void OnEditingDidBegin(object sender, EventArgs e) { }
    }

I added code to look up the attribute on the method from this statement:

    new UITextField().EditingDidBegin += _proxy.OnEditingDidBegin;

This also uncovered a bug in the analyzer:

    --if (attribute.AttributeClass.ContainingNamespace.Name != "System.Diagnostics.CodeAnalysis")
    ++if (attribute.AttributeClass.ContainingNamespace.ToString() != "System.Diagnostics.CodeAnalysis")

In this example `Name` was just `"CodeAnalysis"`. I have no idea why,
but using `.ToString()` instead was successful. All tests pass with this
change, so I'm going with it.
@jonathanpeppers jonathanpeppers merged commit 464abe8 into main Aug 10, 2023
1 check passed
@jonathanpeppers jonathanpeppers deleted the MA0003Suppression branch August 10, 2023 16:29
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.

None yet

1 participant