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
34 stars 18 forks source link

Add optional property for `UsedImplicitlyAttribute` indicating the reason why type is considered to be used implicitly #21

Closed KeterSCP closed 3 months ago

KeterSCP commented 1 year ago

It would be nice to have something like:


[UsedImplicitly(Reason = "Automatically registered by Autofac")]
public class MyClass : IMyClass
{}

API Proposal:

[AttributeUsage(AttributeTargets.All)]
[Conditional("JETBRAINS_ANNOTATIONS")]
public sealed class UsedImplicitlyAttribute : Attribute
{
  public UsedImplicitlyAttribute()
    : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { }

  public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags)
    : this(useKindFlags, ImplicitUseTargetFlags.Default) { }

  public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags)
    : this(ImplicitUseKindFlags.Default, targetFlags) { }

  public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags)
  {
    UseKindFlags = useKindFlags;
    TargetFlags = targetFlags;
  }

  public ImplicitUseKindFlags UseKindFlags { get; }

  public ImplicitUseTargetFlags TargetFlags { get; }

+ public string Reason { get; set; }
}