c# - FileHelper ReadFile() returns null -
i'm working great filehelpers library (version 2.9.9). i've been stuck hours , i'm not able work issue out. load file array of customerclass object. alter order of fields dynamically utilizing delimitedclassbuilder. found reply here on stackoverflow shows how http://stackoverflow.com/a/8833322/767926. i'm not able next answer. works fine if utilize class straight filehelperengine instead of delimitedclassbuilder. please help me out here?
this object create array of csv file:
[delimitedrecord(";")] public class customerclass { public string customerid; public string firstname; public string lastname; } this code i'm using create array:
public void readfile() { delimitedclassbuilder cb = new delimitedclassbuilder("customerclass", ";"); cb.addfield("customerid", typeof(string)); cb.addfield("firstname", typeof(string)); cb.addfield("lastname", typeof(string)); filehelperengine engine = new filehelperengine(cb.createrecordclass()); engine.errormode = errormode.ignoreandcontinue; string filename = @"c:\temp\customerfile.csv"; datatable dt = engine.readfileasdt(filename); // works fine object[] test = engine.readfile(filename) object[]; // works fine customerclass[] customers = engine.readfile(filename) customerclass[]; // returns null (probably because 'cast' invalid, see line below) customers = (customerclass[])engine.readfile(filename); // throws invalidcastexception (unable cast object of type 'customerclass[]' type 'mynamespace.customerclass[]'.) } this file contents:
customerid;firstname;lastname
1;james;brown
2;robert;miller
3;david;green
try qualified class name:
delimitedclassbuilder cb = new delimitedclassbuilder("mynamespace.customerclass", ";");
c# filehelpers
No comments:
Post a Comment