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

Adding analyzer to notify user classes that implement IGrain should inherit from Grain #6941

Merged
merged 3 commits into from
Feb 9, 2021

Conversation

RiskRunner0
Copy link
Contributor

@RiskRunner0 RiskRunner0 commented Feb 7, 2021

Closing #6194

From the feedback, it might be helpful to have an analyzer check to see if a non-abstract class implements IGrain, but doesn't inherit from Grain.

Previously, there was no message from the compiler when a user forgets to derive an implementation from the base Grain class, so this analyzer will generate ORLEANS0003 and inform the user that "Non-abstract classes that implement IGrain should derive from the base class Orleans.Grain".

Example, using HelloWorld from the Samples, where HelloGrain implements IHello, which implements the interface IGrainWithIntegerKey:

image

Another addition is the CodeFixProvider, which provides the user with a potential fix:

image

image

Also works on classes that derive from an abstract class that implements IGrain

image

@RiskRunner0
Copy link
Contributor Author

I'd like some opinions on this, the CodeFixProvider isn't necessary but I think it's a nice to have, but it feels like cheating to use Orleans.Grain instead of adding a using statement and having just Grain.

@RiskRunner0 RiskRunner0 marked this pull request as ready for review February 7, 2021 06:07
@RiskRunner0 RiskRunner0 changed the title Smitty/base analyzer Adding analyzer to notify user classes that implement IGrain should inherit from Grain Feb 7, 2021
@ReubenBond
Copy link
Member

Looks great, thanks Matt! Could you add tests to the Analyzers.Tests project?

@RiskRunner0
Copy link
Contributor Author

Oh, sure didn't see that project, thanks.

@ReubenBond ReubenBond merged commit 6944519 into dotnet:master Feb 9, 2021
@ReubenBond
Copy link
Member

Thanks :) We should add a test for abstract classes, but we can do that later.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants