tags:

views:

74

answers:

2

I'm using [FileHelpers library][1]

[1]: http://www.filehelpers.com/ to process Excel spreadsheet and CSV file.

FileHelpers require user to generate a class in order to extract the data out of the spreadsheet that is mapped exactly as the data on the spreadsheet. It come with a wonderful wizard to generate the class without manually typing it. However, I want to eliminate this process and have the user to type in the field that they want and automatically generate the class for the program to use.

Is it possible to dynamically generate a class and use it during application run time?

+1  A: 

Sure. Look at the System.CodeDom namespace for the tools you need. CodeDom is capable of both generating and loading classes at runtime, and emitting source code to merge into a project.

Jeffrey Hantin
+1  A: 

Yes it is, but the reason to have a class generated would likely be to have compile-time checking of the integrity of types. You can use Jeffrey's link to find more about generating classes at runtime or you can use Reflection.Emit. http://www.codeproject.com/KB/cs/DynamicCodeGeneration2.aspx

Henrik