Domanda

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 :)

È stato utile?

Soluzione

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 }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top