1

I have a little issue when doing the CQLinq query.

I'm trying to get the method that is obsolete with specified fullnames, which means that I want to specify specifically what methods are obsolete by FullName.

The result should pop out 5 matches which means the callMe() method which is obsolete should be included:

enter image description here

However, callMe() is not included when I do this query!

// <Name>Don't use obsolete types, methods or fields</Name>   
warnif count > 0
let oConcreteM =  new String[] {"usageAssembly.Class1.callMe()"}

let obsoleteTypes = Types.Where(t => t.IsObsolete)
let obsoleteMethods = Methods.Where(m => m.IsObsolete 
&& oConcreteM.Contains(m.FullName)).ToHashSet() //TODO HERE!! (Specify callMe())



from m in JustMyCode.Methods.UsingAny(obsoleteTypes).Union(
      JustMyCode.Methods.UsingAny(obsoleteMethods)).Union(
      JustMyCode.Methods.UsingAny(obsoleteFields))

let obsoleteTypesUsed = obsoleteTypes.UsedBy(m)

// Optimization: MethodsCalled + Intersect() is faster than using obsoleteMethods.UsedBy()
let obsoleteMethodsUsed = m.MethodsCalled.Intersect(obsoleteMethods)
let obsoleteFieldsUsed = obsoleteFields.UsedBy(m)
select new { m,obsoleteTypesUsed, obsoleteMethodsUsed, obsoleteFieldsUsed }

With the above query, callMe() is gone, but to get 5 matches, we have to remove "&& oConcreteM.Contains(m.FullName)" code but I don't want to, what I want is to check if the name matches in the Methods Fullname in oConcreteM. Here is what the output gives me:

enter image description here

I hope you guys out there can help me :)

Khiem-Kim Ho Xuan
  • 1,301
  • 1
  • 22
  • 45

1 Answers1

1

So to answer what should have been the question:

I want to list methods defined through a list of strings (defining full names), that are obsolete + for each method matched, list the obsolete types/methods/fields used

let methods=  Application.Methods.WithFullNameIn(
                         "Namespace1.Class1.Method1()", 
                         "Namespace2.Class2.Method2()") // Put more full names here
                         .Where( m => m.IsObsolete)

from m in methods
// Here we cannot easily define m.TypesUsed, hence we use an astute
let obsoleteTypesUsed = m.ParentType.TypesUsed.Where(t => t.IsObsolete).Where(t => t.IsUsedBy(m))
let obsoleteMethodsUsed = m.MethodsCalled.Where(m1 => m1.IsObsolete)
let obsoleteFielsUsed = m.FieldsUsed.Where(f => f.IsObsolete)
select new { m, obsoleteTypesUsed, obsoleteMethodsUsed, obsoleteFielsUsed }
Patrick from NDepend team
  • 13,237
  • 6
  • 61
  • 92
  • still the same, I want the callMe() to be printed out too. But then again, it seems to give med only "4 methods matched", but I want "5 methods matched" – Khiem-Kim Ho Xuan Jul 10 '13 at 13:02
  • which means I want to print out **only** those methods that are given in oConcreteM and ignore any other methods that are obsolete. if it's possible – Khiem-Kim Ho Xuan Jul 10 '13 at 13:09
  • where do you want to *print out only those methods that are given in oConcreteM* ? In the first column or in another column? If in another column, then which code element fo you want to see in the first column? – Patrick from NDepend team Jul 11 '13 at 11:40
  • in the first column. I want to get the results on picture 1 with the code given, I want it to not ignore "callMe()" as it does when I have "&& oConcreteM.Contains(m.FullName)).ToHashSet()" included. – Khiem-Kim Ho Xuan Jul 11 '13 at 13:13
  • I cannot understand the logic of what you want to do. Describe your query in plain English, something like: "I want to list methods with name CallMe() that are using any obsolete types/methods/fields + for each method matched, list the obsolete types/methods/fields used" – Patrick from NDepend team Jul 11 '13 at 13:37
  • I want to list methods that are only contained in a string array (oConcreteMethod) and they are obsolete, do not display those that are not in the string array. + for each method matched, list the obsolete types/methods/fields used – Khiem-Kim Ho Xuan Jul 11 '13 at 13:48
  • What does it mean ? "methods that are only contained in a string array" – Patrick from NDepend team Jul 11 '13 at 16:48
  • oh sorry, I meant the fullname that is stored in a string array like oConcreteM should be able to compare the fullname of the obsolete method that equals the name that is in the string array: "let obsoleteMethods = Methods.Where(m => m.IsObsolete && oConcreteM.Contains(m.FullName)).ToHashSet() //TODO HERE!! (Specify callMe())" – Khiem-Kim Ho Xuan Jul 11 '13 at 21:10
  • and the problem is, the "callMe()" disappears from the output which it should not – Khiem-Kim Ho Xuan Jul 11 '13 at 21:11