I have several enums that contain a lot of values and I know most of them are not used.
I'm trying to write an NDepend CQLinq query to return the enum values that are used in my code base. After finding this SO question I based my query on one of the default queries provided by NDepend:
// <Name>Used enum values</Name>
warnif count > 0
from f in JustMyCode.Fields where
f.ParentNamespace.Name == "My.Namespace" &&
f.NbMethodsUsingMe > 0 &&
f.IsPublic && // Although not recommended, public fields might be used by client applications of your assemblies.
f.IsEnumValue && // The IL code never explicitely uses enumeration value.
f.Name != "value__" && // Field named 'value__' are relative to enumerations and the IL code never explicitely uses them.
!f.HasAttribute("NDepend.Attributes.IsNotDeadCodeAttribute".AllowNoMatch()) &&
!f.IsGeneratedByCompiler // If you don't want to link NDepend.API.dll, you can use your own IsNotDeadCodeAttribute and adapt this rule.
select f
However, NDepend thinks none of the enum values are used. As soon as I replace
f.NbMethodsUsingMe > 0 &&
with
f.NbMethodsUsingMe == 0 &&
all my enum values are listed, which is how I know all the other clauses of the query are OK.
I did notice these two comments on the original query:
f.IsEnumValue && // The IL code never explicitely uses enumeration value.
f.Name != "value__" && // Field named 'value__' are relative to enumerations and the IL code never explicitely uses them.
which could imply that NDepend can't detect usages of an enum value.
Does anyone know if this is a limitation of NDepend? Or even better, of a way to achieve what I want?
Thanks!