다음과 같이 나는 클래스가 :수 없습니다 'System.Collections.IEnumerator'
using System;
using System.Collections;
using System.Collections.Generic;
namespace DataBinding.Schemas.Scenario.ViewModels
{
public class InternationalRowViewDetailsModel: IEnumerable
{
public InternationalRowViewDetailsModel()
{
Country = new System.Collections.Generic.Dictionary<object, object>();
RateEUR = new System.Collections.Generic.Dictionary<object, object>();
RateGBP = new System.Collections.Generic.Dictionary<object, object>();
RateUSD = new System.Collections.Generic.Dictionary<object, object>();
}
public Dictionary<object, object> Country { get; set; }
public Dictionary<object, object> RateEUR { get; set; }
public Dictionary<object, object> RateGBP { get; set; }
public Dictionary<object, object> RateUSD { get; set; }
public IEnumerator GetEnumerator() { return (IEnumerator)this; }
}
}
을 이제 다음과 같이 내가 InternationalRowViewDetailsModel의 값을 반복하는 것을 시도하고있다 :
를foreach (InternationalRowViewDetailsModel currentRow in viewModel)
{
Row newRow = FillInternationalNumberRow(itemRow, currentRow);
tableNode.Rows.Add(newRow);
}
foreach를 사용하여 각 현재 행을 테이블의 열을 채우는 FillInternationalNumberRow 메서드로 보내고 싶습니다.
private static Row FillInternationalNumberRow(Row rowTemplate, InternationalRowViewDetailsModel internationalViewModel)
{
Row newRow = rowTemplate.Clone(true) as Row;
int currentCell = 0;
if (newRow != null)
{
newRow.Cells[currentCell++].FirstParagraph.Runs[0].Text = internationalViewModel.Country.ToString();
newRow.Cells[currentCell++].FirstParagraph.Runs[0].Text = internationalViewModel.RateEUR.ToString();
newRow.Cells[currentCell++].FirstParagraph.Runs[0].Text = internationalViewModel.RateGBP.ToString();
newRow.Cells[currentCell++].FirstParagraph.Runs[0].Text = internationalViewModel.RateUSD.ToString();
}
return newRow;
}
하지만 다음과 같은 오류가 발생합니다 : 'System.Collections.IEnumerator'가
return (IEnumerator) this; 열거자를 결코 정의하지 않았습니다. 오히려 이것을 IEnumerator – Steve
으로 캐스팅하려고하면 foreach 루프에서 InternationalRowViewDetailsModel 클래스를 사용하려고하지만 코드에서 foreach 루프에서 얻고 자하는 것이 명확하지 않은 것입니다. –
@ Scott Morken foreach 루프를 사용하여 각 행의 InternationalRowViewDetailsModel을 통과하려고합니다. – Beginer