JetBrains / JetBrains.Annotations

Annotations to increase the accuracy of JetBrains ReSharper/Rider code inspections
https://www.jetbrains.com/help/resharper/Code_Analysis__Code_Annotations.html
MIT License
30 stars 17 forks source link

Easy integration with Unity? #32

Open NeistH2o opened 1 month ago

NeistH2o commented 1 month ago

Hi there,

I wanted to use the MustDisposeResourceAttribute in my unity project. I couldn't find a way to import this package in the project, so I copied over the relevant files from here to my project. [MustDisposeResource] does work now, but I had to comment parts of Annotations.cs like CanBeNullAttribute, because it led to ambiguous declarations with the already provided annotations in Unity.

Is there any plan to make these attributes available in Unity by default?

EDIT: Maybe there is a way to import nuget packages in unity projects from Rider, sorry if I missed something obvious.

citizenmatt commented 1 month ago

Unfortunately, Unity has their own copy of the annotations and they're public, so become part of Unity's public API. Ideally, they would have added them as internal. Rider/ReSharper would still see the annotations, but they wouldn't become part of their API, and Unity projects could easily add their own copy for their own code.

Unity can keep their copy up to date if they wish, and we have worked with them in the past to update things, but that still requires updating Unity versions and so on.

The best thing to do now is to add a copy of the annotations to your Unity project, and then simply delete any conflicting type definitions. This might not be an elegant solution, but it is fairly straightforward and will work fine.

citizenmatt commented 1 month ago

Oh, and you can use the Copy C# implementation to clipboard button on the Code Annotations settings page in Rider/ReSharper to get a copy of the annotations without having to download them from GitHub. Makes it a little easier.

Screenshot 2024-07-16 at 7 21 23 PM