I have an assembly called 'FileParser' which contains the class 'FileAutoSys' which conforms to the interface 'IFile'.
namespace FileParser
{
class FileAutoSys : IFile
{
public FileAutoSys(ref string[] args)
{
...
}
public FileAutoSys(){}
public void SetValues(ref string[] args)
{
*[same code as in the non-default constructor]*
}
}
I am trying to create an instance of FileAutoSys using Activator.CreateInstance but I am having problems passing args into its constructor.
I can create an instance and set its state using a two-step procedure:
IFile file = (IFile)Activator.CreateInstance(Type.GetType("FileParser.File" + args[0]));
file.SetValues(ref args);
where args[0] is the string 'AutoSys'.
But I don't know how to do it all in one step. I've Googled but I can't find any clear examples of how it's done. MSDN suggests I use the overload:
Activator.CreateInstance(Type, Object[])
but, unhelpfully, it doesn't give any examples and my lack of C# knowledge makes it confusing.
I was hoping someone could explain to me how I should use the abovementioned overload in the context of my example. I am not asking for someone to do it for me as I would like to understand what it is that I should be doing.