I need to return a list of files matching some dynamic criteria. I tried to do this using LINQ.
I found that you can use dynamic LINQ using the System.Linq.Dynamic namespace, which is mentioned in Scott Gug’s Blog .
But I'm not sure if I can use what I need.
So far I get all the files, but I'm not sure where to go from there.
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(SourceLocation);
IEnumerable<System.IO.FileInfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
Now I need to be able to filter these files using some dynamic filters created by the user. e.g. Extension = .txt
Can someone point me in the right direction?
Thank. Martin.
EDIT:
An example in the Dynamic Linq library looks like this:
var query =
db.Customers.Where("City == @0 and Orders.Count >= @1", "London", 10).
OrderBy("CompanyName").
Select("New(CompanyName as Name, Phone)");
. .