NDepend Users Voice

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")]).

119 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Anonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

8 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Thad Peiffer commented  ·   ·  Flag as inappropriate

    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.

  • AdminPatrick Smacchia (Senior Software Engineer, NDepend) commented  ·   ·  Flag as inappropriate

    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 }

  • Michael Baker commented  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    This is also important to distinguish [ComVisible(True)] from [ComVisible(False)], which makes a huge difference...

Feedback and Knowledge Base