Question

I am trying to create another custom query with NDepend, but cannot figure it out.

Here's in pseudocode what I'd like to query:

var list
foreach type t
    int newCount = 0
    foreach type u in t.TypesUsed
        if "new"-operator of u is called anywhere within t
            newCount++;
    end foreach
    list.Add( new Tuple<Type, int>(t, newCount) )
end foreach
return list    

I'd like to know how many times the "new"-operator is called anywhere within a type.

I am very new to the syntax of the NDepend queries. So some hints would help a lot :)

Thanks!

Était-ce utile?

La solution

You can try this query, that lists for each type t, all types instantiated in the code of t (i.e a type is instantiated when one of its constructor is called through the new operator).

from t in JustMyCode.Types
let typesInstantiated = from tUsed in t.TypesUsed 
                        where tUsed.Constructors.Any(c => c.IsUsedBy(t))
                        select tUsed
where typesInstantiated.Count() > 0
select new { t, typesInstantiated }

The result looks like:

Types instantiated

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top