question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: External ReSharper Annotations

See original GitHub issue

ReSharper or Rider - two very commonly used utilities for programming in c# - looks through your code to determine whether or not something is used or not, and “complains” if it’s not. image.

And since Endpoints(And Validators) are never directly accessed in the code, this warning will always show up on all endpoints and validator classes

There are three ways of removing this warning:

  1. Actually using it (which does not make sense in this context)
  2. Adding the [UsedImplicitly] Attribute from JetBrains.Annotations to the class directly*, or to the base class using the ImplicitUseTargetFlags.WithInheritors parameter on the Attribute image
  3. Using so-called External Annotations. Jetbrains has some built-in ones, which they share on GitHub

As these Attributes do not get compiled when you build - as they’re entirely there to help the developer - I do not believe simply adding these to the base classes does anything (Although, I might be wrong). Because of this, I believe you, as a library author, realistically only have one way of adding them, and that’s option 3 - External Annotations.

Now, I don’t know how to distribute these External Annotations - if you have to make a separate FastEndpoints.ExternalAnnotations NuGet package, or if you could add them to the base FastEndpoints package, or what have you. You could also maybe send a Pull Request to JetBrains’ own list of External Annotations and ask them to add it to their list. However you do it is up to you, really.

I have an ExternalAnnotations file I made yesterday (This does not include the new features added in 4.5.0, so you’d have to add those yourself, or I could help if this is something you want to pursue).

Here’s the 4.4.0 file (This makes Access implicit for all inheritors of the various Endpoints/Validators(That’s what the 1 and 4 means respectively)). I never considered before writing this that maybe I could add it to the BaseEndpoint directly, removing a lot of boilerplate. I’ll test this and update the post

<?xml version="1.0" encoding="utf-8"?>
<assembly name="FastEndpoints">

	<!-- <Endpoints> -->
	<member name="T:FastEndpoints.Endpoint`3">
		<attribute
			ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseKindFlags,JetBrains.Annotations.ImplicitUseTargetFlags)">
			<argument>1</argument>
			<argument>4</argument>
		</attribute>
	</member>
	<member name="T:FastEndpoints.Endpoint`2">
		<attribute
			ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseKindFlags,JetBrains.Annotations.ImplicitUseTargetFlags)">
			<argument>1</argument>
			<argument>4</argument>
		</attribute>
	</member>
	<member name="T:FastEndpoints.EndpointWithoutRequest">
		<attribute
			ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseKindFlags,JetBrains.Annotations.ImplicitUseTargetFlags)">
			<argument>1</argument>
			<argument>4</argument>
		</attribute>
	</member>
	<member name="T:FastEndpoints.EndpointWithoutRequest`1">
		<attribute
			ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseKindFlags,JetBrains.Annotations.ImplicitUseTargetFlags)">
			<argument>1</argument>
			<argument>4</argument>
		</attribute>
	</member>
	<member name="T:FastEndpoints.EndpointWithMapping`3">
		<attribute
			ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseKindFlags,JetBrains.Annotations.ImplicitUseTargetFlags)">
			<argument>1</argument>
			<argument>4</argument>
		</attribute>
	</member>
	<!-- </End...points> -->

	<!-- <Validators> -->
	<member name="T:FastEndpoints.Validator`1">
		<attribute
			ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseKindFlags,JetBrains.Annotations.ImplicitUseTargetFlags)">
			<argument>1</argument>
			<argument>4</argument>
		</attribute>
	</member>
	<!-- <Validators/>-->
</assembly>

* This is what I’ve been doing so far. For reference, these attributes can also be applied to fields, properties (including specifically on get, set, init), methods, and so on - practically everywhere you can add Attributes

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
dj-nitehawkcommented, Aug 14, 2022

yep sounds like a plan. will push a new beta out first thing tomorrow morning. gonna doze off for the day now. ciao!

0reactions
dj-nitehawkcommented, Aug 15, 2022

beautiful… i’ll close the issue for now. feel free to reopen if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

External annotations | ReSharper Documentation
To study ReSharper external annotations, look at XML files in subdirectories of the [ReSharper installation directory]\ExternalAnnotations ...
Read more >
JetBrains ReSharper External Annotations
The default set of external annotations that ships with ReSharper and Rider.
Read more >
Where to copy Resharper external annotation XML files ...
After discussing with @citizenmatt I have decided to ship my annotations along the dll. He had a good point, adding it on the...
Read more >
Annotating Nulls in C# - Kill All Defects
This library contains a few attributes that you can use to annotate your classes, methods, properties, fields, and parameters. While these are ...
Read more >
Leveraging ReSharper annotations - Thomas Levesque
Instead, ReSharper uses external annotations. These are XML files that are shipped with R# and contain a lot of metadata about .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found