首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IEnumerator实现问题

IEnumerator实现问题
EN

Stack Overflow用户
提问于 2010-07-24 10:32:17
回答 2查看 170关注 0票数 0

我有这样的代码:

代码语言:javascript
复制
public class Check21CSVRecord
{

    public string TransactionType;
    public string TransactionCurrency;
    public string Reference;
    public string PaymentType;

    // date of transaction                
    public string TransactionDate;

    public string Notes;

    // customer data goes here
    public string CustomerFirstName;
    public string CustomerInitial;
    public string CustomerLastName;
    public string CustomerStreetAddress;
    public string CustomerCity;
    public string CustomerState;
    public string CustomerZIPCode;

    [FieldConverter(ConverterKind.Date, "MM/dd/yy")] 
    public DateTime CustomerDateBirth;
    public string CustomerCountry;
    public string CustomerEmail;
    public string CustomerPhone;
    public string CustomerIPAddress;

    // MICR line goes here
    public string AuxiliaryOnUs;
    public string ExternalProcessingCode;
    public string PayorBankRoutingNumber;
    public string PayorBankRoutingNumberCheckDigit;
    public string OnUs;

    // check amount
    [FieldConverter(ConverterKind.Double)]
    public double Amount;

    // what account to credit
    public string CreditAccountNumber;

    public string FrontImagePath;
    public string BackImagePath;

    // used to define if we have image or should build it dynamically
    public bool IsDynamicImage{
        get
        {
            return (FrontImagePath.Length == 0 && BackImagePath.Length == 0);
        }
    }
}


public class DataProvider <T>:  IEnumerator
{
    private FileHelperEngine CSVReader;

    private T currentRecord;
    private int currentIndex;
    private string file;
    private T[] collection = new T[5000];

    public DataProvider(string CSVFile)
    {
        CSVReader = new FileHelperEngine(typeof(T));
        collection = CSVReader.ReadFile(file) as T[];

        currentRecord = default(T);            
        file = CSVFile;
        Reset();
    }

    public bool MoveNext()
    {
        if (++currentIndex >= collection.Count())
        {
            return false;
        }
        else
        {   
            currentRecord = collection[currentIndex];
        }
        return true;

    }

    public void Reset()
    {
        currentIndex = -1;
    }

    public void Dispose()
    {

    }

    public T Current
    {
        get
        {
            return currentRecord;
        }
    }

    object System.Collections.IEnumerator.Current
    {
        get { return currentRecord; }
    }
}

当我编译的时候-一切都很好,但是当我调用这个类时:

代码语言:javascript
复制
 var input = new DataProvider<Check21CSVRecord>("../../../../Artifacts/IncomingData/Check21/check21.csv");
 while (input.MoveNext())
 {
       Console.WriteLine(input.Current.CustomerFirstName);
 }

我遇到了以下问题:http://screencast.com/t/NDBkNTNkMjkt

有什么办法解决这个问题吗?

谢谢,德米特里

EN

回答 2

Stack Overflow用户

发布于 2010-07-24 10:35:07

您应该首先分配file

代码语言:javascript
复制
public DataProvider(string CSVFile)
{            
    file = CSVFile;
    CSVReader = new FileHelperEngine(typeof(T));
    collection = CSVReader.ReadFile(file) as T[];

    currentRecord = default(T);
    Reset();
}
票数 1
EN

Stack Overflow用户

发布于 2010-07-24 10:35:31

是的,因为'file‘是空的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3323574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档