This has nothing to do with LINQ. It is purely C# lambda expressions + List.
In this case, Predicate
1is not a *field name*, but instead, a type, more precisely
System.Predicate`.
It looks to me that you want to analyze method bodies looking for references to this type. Even though this may be possible to achieve through reflection it will be much easier you you can use Mono.Cecil; in that case you can use something like (please, not that this code is not complet in any ways... you'd need to account for errors, static fields, etc):
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
class Bar
{
void Foo(List<int> items)
{
// A non sense expression :)
var r = items.FindAll(i => i % 2 == 0 || i.ToString() == "A");
}
static void Main()
{
var a = AssemblyDefinition.ReadAssembly(typeof(Bar).Assembly.Location);
var allMethods = a.MainModule.GetTypes().SelectMany(t => t.Methods);
// find instructions referencing System.Predicate<T>
var allMethodsReferencingSystemPredicate = allMethods.Where(m => m.Body.Instructions.Any(i => i.OpCode == OpCodes.Newobj && i.Operand.ToString().Contains("System.Predicate`1")));
foreach(var m in allMethodsReferencingSystemPredicate)
{
System.Console.WriteLine($"Analyzing {m}");
var instReferencingSystemPredicate = m.Body.Instructions.Where(i => i.OpCode == OpCodes.Newobj && i.Operand.ToString().Contains("System.Predicate`1"));
foreach(var inst in instReferencingSystemPredicate)
{
System.Console.WriteLine($"Checking {inst} / {inst.Previous}");
if (inst.Previous.OpCode != OpCodes.Ldftn)
{
System.Console.WriteLine($"Something went wrong. Expected LdFnt, got {inst.Previous.OpCode} in instruction {inst.Previous}");
continue;
}
// get the method being referenced.
var method = ((MethodReference) inst.Previous.Operand).Resolve();
// Analyze the method body looking for calls to `ToString()` (you will replace this with your own checks...)
foreach(var methodInst in method.Body.Instructions)
{
//System.Console.WriteLine($"Checking: {methodInst}");
if ( (methodInst.OpCode == OpCodes.Callvirt || methodInst.OpCode == OpCodes.Call) && methodInst.Operand.ToString().Contains("ToString()"))
{
System.Console.BackgroundColor = System.ConsoleColor.DarkCyan;
System.Console.WriteLine($"{method} (used in {m}) references ToString(): {methodInst}");
}
}
}
}
}
}