Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can the [UsedImplicitly] attribute be used on a namespace level?

ReSharper has a [UsedImplicitly] attribute which ignores properties that are not being directly referenced. This is recommended to be used by JetBrains: https://www.jetbrains.com/help/resharper/2016.1/MemberCanBePrivate.Global.html

Is there any way to apply this attribute at a namespace level? Or is there another way to ignore all classes within a given namespace (and possibly all child namespaces)?

like image 881
Anshul Avatar asked Nov 04 '16 22:11

Anshul


1 Answers

This answer does not answer the question but it might be helpful.

I have an attribute called PluginEntryPointAttribute.

public class PluginEntryPointAttribute : Attribute 
{
}

And my code used to look like this:

[PluginEntryPointAttribute]
[UsedImplicitly]
public void SomeEntryMethod()
{
    // code
}

I need the UsedImplicitly attribute so that ReSharper does not mark my SomeEntryMethod as not used.


My new code looks like this thanks to [JetBrains.Annotations.MeansImplicitUse]:

[JetBrains.Annotations.MeansImplicitUse]
public class PluginEntryPointAttribute : Attribute 
{
}

Now on my code, I do not need to include the UsedImplicitly attribute:

[PluginEntryPointAttribute]
// [UsedImplicitly] no need to use it because PluginEntryPointAttribute has the MeansImplicitUse attribute
public void SomeEntryMethod()
{
    // code
}
like image 78
Tono Nam Avatar answered Nov 09 '22 14:11

Tono Nam