简体   繁体   English

无法从“System.Collections.Generic.IEnumerable”转换<string> &#39; 到 &#39;T&#39;

[英]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> to T无法从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.

相关问题 TreeView:无法从&#39;System.Collections.Generic.IEnumerable转换 <string> &#39;到&#39;System.Collections.Generic.IEnumerable - TreeView: Cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'System.Collections.Generic.IEnumerable 无法从&#39;System.Collections.Generic.IEnumerable转换为System.Collections.Generic.IEnumerable <string> - Cannot convert from 'System.Collections.Generic.IEnumerable to System.Collections.Generic.IEnumerable<string> 无法从“ System.Collections.Generic.IEnumerable”转换为System.Collections.Generic.IEnumerable <string> - cannot convert from 'System.Collections.Generic.IEnumerable' to System.Collections.Generic.IEnumerable<string> 无法从&#39;System.Collections.Generic.IEnumerable转换 <char> &#39;到&#39;字符串&#39; - cannot convert from 'System.Collections.Generic.IEnumerable<char>' to 'string' 无法从&#39;System.Collections.Generic.IEnumerable转换 <int> &#39;到&#39;System.Collections.Generic.IEnumerable <int?> “ - Cannot convert from 'System.Collections.Generic.IEnumerable<int>' to 'System.Collections.Generic.IEnumerable<int?>' 无法从“System.Collections.IList”转换为“System.Collections.Generic.IEnumerable”<t> '</t> - Cannot convert from 'System.Collections.IList' to 'System.Collections.Generic.IEnumerable<T>' 无法从&#39;System.Collections.Generic.IEnumerable转换 <System.Collection.Generic.List<char> &gt;字符串[] - Cannot convert from 'System.Collections.Generic.IEnumerable<System.Collection.Generic.List<char>> to string[] 从&#39;string&#39;转换为&#39;System.Collections.Generic.IEnumerable <string> - Convert from 'string' to 'System.Collections.Generic.IEnumerable<string> Linq无法从&#39;System.Collections.Generic.IEnumerable转换 <string> &#39;to&#39;string []&#39; - Linq cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string[]' 收到此错误“参数 2 无法从 'System.Collections.Generic.IEnumerable string ' 转换为 'string '” - Getting this error “Argument 2 cannot convert from 'System.Collections.Generic.IEnumerable string ' to 'string '”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM