Search code examples
c#genericsreflectionfilehelpers

Upgraded FileHelpers library and now my code is obsolete


I use reflection to specify the class name dynamically when I do file imports using FileHelpers like this ...

Assembly assembly = Assembly.GetExecutingAssembly();
AssemblyName assemblyName = assembly.GetName();
Type t = assembly.GetType(assemblyName.Name + ".FileDefinitions." + className);
FileHelperEngine engine = new FileHelperEngine(t);

After getting the latest version of the library what I was doing above now considered "obsolete"

The implementation has been changed to generics in this manner

FileHelperEngine<myImportDefinitionClass> = new
                                 FileHelperEngine<myImportDefinitionClass>();

but I am not sure how to specify the myImportDefintionClass dynamically at runtime, using the original reflection code doesn't work.

UPDATE : After trying Paul's code I would now need to be able to do access the methods or whatever within the FileHelpers class such as (this part doesn't compile)

fileHelperEngine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;

importData = fileHelperEngine.ReadFileAsDT(filepath);

But I am not real clear about what is actually going on. Any links to better understand the generics concepts would be appreciated also.


Solution

  • Breadtruck

    I commited the changes with the [Obsolote] attribute yesterday, in fact was to check some examples of the lib for the next release, but are removed now.

    You can do an SVN update and recompile it to avoid the warning, sorry for the problems :(

    Marcos