我有一个 ModuleViewModel 的 readOnlyCollection,我想用 linq 检索包含在我的集合中的特定 ModuleViewModel。
这里是我收藏的声明:
public ReadOnlyCollection<ModuleViewModel> colModuleViewModel { get; set; }
colModuleViewModel = new ReadOnlyCollection<ModuleViewModel>(
(from mod in currentProg.Tests.Values
select new ModuleViewModel(mod))
.ToList<ModuleViewModel>());
我的 ModuleViewModel 类:
public class ModuleViewModel : INotifyPropertyChanged
{
readonly ReadOnlyCollection<ModuleViewModel> _children;
readonly ModuleViewModel _parent;
readonly Module _module;
public ReadOnlyCollection<ModuleViewModel> Children
{
get { return _children; }
}
bool _isExpanded;
bool _isSelected;
public ModuleViewModel(Module module)
: this(module, null)
{
}
private ModuleViewModel(Module module, ModuleViewModel parent)
{
_module = module;
_parent = parent;
if (module is Task)
{
_children = new ReadOnlyCollection<ModuleViewModel>(
(from mod in ((Task)module).Tests.Values
select new ModuleViewModel(mod, this))
.ToList<ModuleViewModel>());
}
else
{
_children = null;
}
}
public ModuleViewModel Parent
{
get { return _parent; }
}
public string Name
{
get { return _module.Name; }
}
public string Id
{
get { return (_module is Test ? ((Test)_module).Id : ((Task)_module).Id); }
}
}
我有 ModuleViewModel 的 ID:
string idMod = ((Module)currentProgram.finalDico[data.ToString()]).Id;
我想检索 Id == idMod 的 ModuleViewModel
object obj = from c in colModuleViewModel 在哪里??选择 c;