cannot convert from 'System.Collections.Generic.IEnumera

本文关键字:System Collections Generic IEnumera convert from cannot | 更新日期: 2023-09-27 18:11:31

我希望这是一些非常简单的东西,我只是完全错过了,但我似乎无法弄清楚这里需要改变什么。

不能从System.Collections.Generic.IEnumerable<string>转换为T

编译错误来自这里的这个块,特别是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;

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;
}

cannot convert from 'System.Collections.Generic.IEnumera

什么是keyFilter?我猜它返回IEnumerable,这意味着字典上没有Contains()重载。您可能需要以下内容:

var processList = 
data.Where(item => keyFilter(item.DataItem).Any(key => idDictionary.ContainsKey(key))).ToList()
相关文章: