c# - FileHelpers Library: AfterReadRecord Compilation Error -
i'm hoping there's expert in using filehelpers library here.
i'm using 2.9.9 stable version nuget , trying use afterreadrecord event handler test if fields empty.
the code have shown in simplified form below:
public class test { public class myclass { public string name; } public static void engine_afterreadrecord(enginebase engine, filehelpers.events.afterreadeventargs<myclass> e) { if (string.isnullorwhitespace(e.record.name)) { throw new invaliddataexception("name required"); } } public void readcsv() { filehelperengine engine = new filehelperengine(typeof(myclass)); engine.options.ignorefirstlines = 1; engine.errormanager.errormode = errormode.saveandcontinue; engine.afterreadrecord += new filehelpers.events.afterreadhandler<myclass>(engine_afterreadrecord); } }
there's compilation error on last line in readcsv file. error is:
cannot implicitly convert type 'filehelpers.events.afterreadhandler<myclass>' 'filehelpers.events.afterreadhandler<object>'
i'm stuck. helpers?
jake
the problem u using version of engines don't use generics using generics in handler
try this:
var engine = new filehelperengine<myclass>(); engine.options.ignorefirstlines = 1; engine.errormanager.errormode = errormode.saveandcontinue; engine.afterreadrecord += new filehelpers.events.afterreadhandler<myclass>(engine_afterreadrecord);
Comments
Post a Comment