Being able to read attribute property values
Being able to filter on attribute property values.
One example is to check categories on Test methods (i.e. the value from [TestCategory("IntegrationTest")]).
-
@Peter sorry this feature is not available yet
-
Peter Baumann commented
I don't find the method GetAttributeTag from your expample posted on "April 3, 2018 9:19 AM" by Patrick Smacchia.
Any hint on what I am missing? -
Mohammed Elmahdy commented
I'm very frustrated with NDepend support actually, almost every feature I need, I find it suggested by other people more than 4 years ago and not implemented till now !!
Unfortunately, I can't recommend NDepend to my enterprise -
>The question is, shall you and when will you provide this?
Yes this is high on our TODO list, hopefully in 2020
-
Cary commented
Vote up also for demanding this feature. I have been developing a function which needs to read the values assigned to the attribute which is attached to a class. Unfortunately up to now I still cannot find such an API provided by NDepend. APIs like this would be very practical especially when the dependencies between types are established through attributes instead of interfaces. The question is, shall you and when will you provide this?
-
Thanks Thad, we work hard to deliver value several times a year,
https://www.ndepend.com/whatsnewPrioritizing new features is not an easy task and your feedback matters to us, thanks
-
Thad Peiffer commented
This is the #2 most voted feature request and hasn't been addressed since it was requested in 2014? NDepend 2019 adds no value-add features (in my opinion). A useful feature like this is the only reason I could recommend to my company that we upgrade.
-
We started investigating about supporting attribute value
Your feedbacks here or at support at ndepend dot com will be welcome.--
First we have a restriction: For example from attribute
[ComVisible(true)]
we won't be able to bind the value "true" with the property "ComVisibleAttribute.Value"
because the info to bind ctor "visibility" parameter to the property "ComVisibleAttribute.Value"
is enclosed in the IL of the attribute class that we don't plan to read at the moment
because at this point in analysis, we only have access to the attribute class reference,
not access to the attribute class definition (with th IL)--
However this example would work fine (no matter if Level is a property or a field)
[ComponentCriticality (Level= CriticalityLevel.High)]
coz we know about property/field name Level
and it could be queried this way:// <Name>Classes with a Criticality High should be 100% covered by tests</Name>
from t in Application.Types
where t.GetAttributeTag("Namespace.ComponentCriticalityAttribute") // Returns a IAttributeTag or null
.IfNotNullGetPropertyNamed("Level") // Returns a IAttributeTagProperty or null
.IfNotNullGetValueAsEnumValue() // Returns a IField (for the enum value) or null
.IfNotNullGetSimpleName() == "High"
&& t.PercentageCoverage < 100
select new { t, t.PercentageCoverage }or this way
// <Name>Classes with a Criticality High should be 100% covered by tests</Name>
from t in Application.Types
where t.GetAttributeTag("Namespace.ComponentCriticalityAttribute") // Returns a IAttributeTag or null
.IsNotNullAnd(attrTag => attrTag.GetPropertyNamed("Level") // attrTag is a IAttributeTag
.IsNotNullAnd(prop => prop.ValueAsEnumValue // prop is a IAttributeTagProperty
.IsNotNullAnd(val => val.SimpleName == "High"))) // val is a IField
&& t.PercentageCoverage < 100
select new { t, t.PercentageCoverage } -
This feature is demanded, we will definitely implement it, it is just a matter of time, hopefully next year
-
Toni Voter commented
I also would appreciate this feature in ndepend. Is there any change so far?
-
Michael Baker commented
I would like to see any attribute values considered for code diff and so reflected in the WasChanged or WasCodeChanged methods. Currently attribute values are not considered in code diff.
-
Robert Leahey commented
Indeed, being able to evaluate the values of any attribute would be important...
[TestCategory("IntegrationTest")]
[ComVisible(True)]
or...
[TestCase( new [] { Allowed.Reserved, Allowed.Public }, new [] {1,2,4 }, TestName = "Reserved/Public")]Just to make your lives difficult...
-
Thomas W. commented
This is also important to distinguish [ComVisible(True)] from [ComVisible(False)], which makes a huge difference...