When building a library that is intended to be shipped to others, we can include the JetBrains Annotations source code directly in our project (or compile with the JETBRAINS_ANNOTATIONS flag set). As long as the JetBrains.Annotations namespace exists, Rider and ReSharper will make use of them. In other words: it is there while developing and your team can use the annotations, but it’s gone when compiled. The NuGet package uses the attribute to ensure the annotations are not compiled into the resulting assembly. Now which option to pick…Īs a rule of thumb, it’s usually best to reference the JetBrains.Annotations NuGet package when a project is not intended to be shared outside a development team. We can reference the JetBrains Annotations in two ways: by adding the official JetBrains.Annotations NuGet package to our project, or by adding the annotations to the source code of our project. Good for me: my colleague Matt already wrote about adding JetBrains Annotations in ReSharper a while ago, so let’s focus on Rider here. How to add JetBrains Annotations to our own codebase? The IDE will use that information to provide additional code completion, will check for string format placeholders, etc. NET base classes have been annotated, as well as popular frameworks such as Caliburn.Micro, NUnit, Nancy’s Razor view engine, xUnit, log4net and so on.įor example, an annotation tells Rider and ReSharper that has a first argument that is a “string format” method. Rider and ReSharper ship with a copy of the XML annotations we have open-sourced on GitHub. All of the. Only one way to tell the engine: annotations.Īnnotations can exist as attributes in our code, as we have seen, or as XML files. Code analysis may warn us that a value can be null, but maybe the underlying code never returns null at all. In our previous post, we saw that the ReSharper engine knew we were working with strings, but only we as the author of that code knew these strings were controllers and actions. We have already seen that we can make this mechanism smarter by telling Rider and ReSharper what we mean. Rider and ReSharper’s code analysis and inspections are very smart on their own and help find code smells, dead code, potential compile time or run time errors, and more. Better null checks, string formatting and path completion with JetBrains Annotationsīefore we look at how to add JetBrains Annotations to our code, let’s take one step back and look at what they are.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |