我希望這是一件非常簡單的事情,我完全錯過了,但我似乎無法弄清楚需要在這裏改變什麼。無法從'System.Collections.Generic.IEnumerable <string>'轉換爲'T'
不能轉換從
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;
}
請證明給這個編譯器錯誤的確切聲明,並給出相應的聲明('data','keyFilter')。 – CodeCaster
沒有理由讓你的班級成爲通用的,就像現在這樣。你只在一個特定點('ImportItem')使用類型參數,即使這樣,你實質上斷言'T'將是'IEnumerable'。你是不是要將'DataItem'聲明爲'T'? –