I have a situation where I have table that contains an id field and a class name field:
id class_name
1 ParseExcelFile.dll
2 ParseTextFile.dll
What I want to do is load one of these classes dynamically from a windows application based on the id I request from the database. I know that I can instantiate either one using reflection and CreateInstance. However, I want to use (I believe) an interface to reference a parsing routine in whatever class is instantiated. Something like this:
My goal here is to be able to reference the method "FormatFile" despite whatever class I call. How do I implement an interface in this case? More specifically, do I compile a separate Class Library project just containing my interface code for the "FormatFile" function and then implement it in each of the parsing classes (as well as add it to the Reference section)? Or is my architecture altogether too complex? Thanks in advance.
id class_name
1 ParseExcelFile.dll
2 ParseTextFile.dll
What I want to do is load one of these classes dynamically from a windows application based on the id I request from the database. I know that I can instantiate either one using reflection and CreateInstance. However, I want to use (I believe) an interface to reference a parsing routine in whatever class is instantiated. Something like this:
Code:
objAssembly = System.Reflection.Assembly.GetExecutingAssembly()
objParser = objAssembly.CreateInstance(strClassName)
lngStatus = objParser.FormatFile(strFileName)
My goal here is to be able to reference the method "FormatFile" despite whatever class I call. How do I implement an interface in this case? More specifically, do I compile a separate Class Library project just containing my interface code for the "FormatFile" function and then implement it in each of the parsing classes (as well as add it to the Reference section)? Or is my architecture altogether too complex? Thanks in advance.