From 21eb9bf1fafa5fe80856d407d9e73cea3ca514c5 Mon Sep 17 00:00:00 2001 From: Julian Bildner Date: Mon, 13 Mar 2023 10:12:07 +0100 Subject: [PATCH 1/2] MeansImplicitUse for NetDaemonAppAttribute --- .../Common/Attributes/NetDaemonAppAttribute.cs | 3 +++ src/AppModel/NetDaemon.AppModel/NetDaemon.AppModel.csproj | 1 + 2 files changed, 4 insertions(+) diff --git a/src/AppModel/NetDaemon.AppModel/Common/Attributes/NetDaemonAppAttribute.cs b/src/AppModel/NetDaemon.AppModel/Common/Attributes/NetDaemonAppAttribute.cs index 59810945d..706d7476a 100644 --- a/src/AppModel/NetDaemon.AppModel/Common/Attributes/NetDaemonAppAttribute.cs +++ b/src/AppModel/NetDaemon.AppModel/Common/Attributes/NetDaemonAppAttribute.cs @@ -1,8 +1,11 @@ +using JetBrains.Annotations; + namespace NetDaemon.AppModel; /// /// Marks a class as a NetDaemonApp /// +[MeansImplicitUse] [AttributeUsage(AttributeTargets.Class)] public sealed class NetDaemonAppAttribute : Attribute { diff --git a/src/AppModel/NetDaemon.AppModel/NetDaemon.AppModel.csproj b/src/AppModel/NetDaemon.AppModel/NetDaemon.AppModel.csproj index 9573d5e20..78e813139 100644 --- a/src/AppModel/NetDaemon.AppModel/NetDaemon.AppModel.csproj +++ b/src/AppModel/NetDaemon.AppModel/NetDaemon.AppModel.csproj @@ -20,6 +20,7 @@ + From 342d07b67a251ea12d53449ed54a7f06c28c76a1 Mon Sep 17 00:00:00 2001 From: Julian Bildner Date: Tue, 14 Mar 2023 14:27:14 +0100 Subject: [PATCH 2/2] add generated JetBrainsCodeAnnotations directly for MeansImplicitUse to get rid of nuget dependency --- .../Attributes/JetBrainsCodeAnnotations.cs | 102 ++++++++++++++++++ .../NetDaemon.AppModel.csproj | 1 - 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/AppModel/NetDaemon.AppModel/Common/Attributes/JetBrainsCodeAnnotations.cs diff --git a/src/AppModel/NetDaemon.AppModel/Common/Attributes/JetBrainsCodeAnnotations.cs b/src/AppModel/NetDaemon.AppModel/Common/Attributes/JetBrainsCodeAnnotations.cs new file mode 100644 index 000000000..efbd7d708 --- /dev/null +++ b/src/AppModel/NetDaemon.AppModel/Common/Attributes/JetBrainsCodeAnnotations.cs @@ -0,0 +1,102 @@ +/* MIT License + +Copyright (c) 2016 JetBrains http://www.jetbrains.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. */ + +#nullable disable + +// ReSharper disable UnusedType.Global + +#pragma warning disable 1591 +// ReSharper disable UnusedMember.Global +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable IntroduceOptionalParameters.Global +// ReSharper disable MemberCanBeProtected.Global +// ReSharper disable InconsistentNaming +// ReSharper disable once CheckNamespace +namespace JetBrains.Annotations; + +/// +/// Can be applied to attributes, type parameters, and parameters of a type assignable from . +/// When applied to an attribute, the decorated attribute behaves the same as . +/// When applied to a type parameter or to a parameter of type , +/// indicates that the corresponding type is used implicitly. +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter | AttributeTargets.Parameter)] +internal sealed class MeansImplicitUseAttribute : Attribute +{ + public MeansImplicitUseAttribute() + : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } + + public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags) + : this(useKindFlags, ImplicitUseTargetFlags.Default) { } + + public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags) + : this(ImplicitUseKindFlags.Default, targetFlags) { } + + public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) + { + UseKindFlags = useKindFlags; + TargetFlags = targetFlags; + } + + public ImplicitUseKindFlags UseKindFlags { get; } + + public ImplicitUseTargetFlags TargetFlags { get; } +} + +/// +/// Specifies the details of implicitly used symbol when it is marked +/// with or . +/// +[Flags] +internal enum ImplicitUseKindFlags +{ + Default = Access | Assign | InstantiatedWithFixedConstructorSignature, + /// Only entity marked with attribute considered used. + Access = 1, + /// Indicates implicit assignment to a member. + Assign = 2, + /// + /// Indicates implicit instantiation of a type with fixed constructor signature. + /// That means any unused constructor parameters won't be reported as such. + /// + InstantiatedWithFixedConstructorSignature = 4, + /// Indicates implicit instantiation of a type. + InstantiatedNoFixedConstructorSignature = 8, +} + +/// +/// Specifies what is considered to be used implicitly when marked +/// with or . +/// +[Flags] +internal enum ImplicitUseTargetFlags +{ + Default = Itself, + Itself = 1, + /// Members of the type marked with the attribute are considered used. + Members = 2, + /// Inherited entities are considered used. + WithInheritors = 4, + /// Entity marked with the attribute and all its members considered used. + WithMembers = Itself | Members +} \ No newline at end of file diff --git a/src/AppModel/NetDaemon.AppModel/NetDaemon.AppModel.csproj b/src/AppModel/NetDaemon.AppModel/NetDaemon.AppModel.csproj index 78e813139..9573d5e20 100644 --- a/src/AppModel/NetDaemon.AppModel/NetDaemon.AppModel.csproj +++ b/src/AppModel/NetDaemon.AppModel/NetDaemon.AppModel.csproj @@ -20,7 +20,6 @@ -