[英]cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'T'
I hope this is something really simple that I am just completely missing, but I can't seem to figure out what needs to be changed here.我希望这是我完全错过的非常简单的事情,但我似乎无法弄清楚这里需要改变什么。
cannot convert from
System.Collections.Generic.IEnumerable<string>
toT
无法从
System.Collections.Generic.IEnumerable<string>
转换为T
The compile error is coming from this block here, specifically item.DataItem:编译错误来自这里的这个块,特别是 item.DataItem:
public List<ImportItem<T>> ProcessReportResult(CSVTable resultData, ICollection<ImportItem<T>> data, Func<T, IEnumerable<string>> keyFilter)
{
WriteLog("{1}{0} records found.{1}", resultData.Rows.Length, Environment.NewLine);
//key = Order Number; value = Order ID
var idDictionary = resultData.Rows.Select((row => row.Split(','))).ToLookup(id => id[0], id => id[1]);
idDictionary.ForEach(id => WriteLog("Input Id = {0} - Matching record Id = {1}", id.Key));
var processList = data.Where(item => idDictionary.Contains(keyFilter(item.DataItem))).ToList();
processList.ForEach(item => item.Id = idDictionary[keyFilter(item.DataItem)]);
return processList;
The declaration of DataItem is coming from within this class here: DataItem 的声明来自这里的这个类:
public class ImportItem<T> : INotifyPropertyChanged
{
public IEnumerable<string> DataItem
{
get; set;
}
private bool visible;
public bool Visible
{
get { return visible; }
set
{
visible = value;
RaisePropertyChanged("Visible");
}
}
public string ErrorMessage { get; set; }
public IEnumerable<string> Id
{
get; set;
}
public Status Status { get; set; }
public ImportItem(T item)
{
DataItem = (IEnumerable<string>) item;
visible = true;
}
private void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
What is keyFilter?什么是关键过滤器? I'm guessing it returns IEnumerable, which means that there's no Contains() overload on a Dictionary for it.
我猜它会返回 IEnumerable,这意味着它的字典上没有 Contains() 重载。 You probably want the following:
您可能需要以下内容:
var processList =
data.Where(item => keyFilter(item.DataItem).Any(key => idDictionary.ContainsKey(key))).ToList()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.