这是我的应用程序中使用匿名委托搜索属性集合的当前代码:
public class MyObject
{
public MyObject() { }
public string MyObjectId { get; set; }
public List<MySubObject> SubObjects { get; set; }
}
public class MySubObject
{
public MySubObject() { }
public string MySubObjectId { get; set; }
}
public List<MyObject> Search(string input)
{
List<MyObject> AllObjects = Data.GetAllObjects();
List<MyObject> SearchResults = new List<MyObject>();
SearchResults = AllObjects.FindAll
(
delegate(MyObject o)
{
return e.MyObjectId.Equals(input)
}
);
if (SearchResults .Count.Equals(0))
SearchResults = null;
return SearchResults ;
}
我想修改匿名委托以通过MySubObject.MySubObjectId
通用列表中的属性而不是属性进行搜索MyObjectId
。我将如何修改匿名委托中的代码来完成此操作?