Automation Interfaces & .NET Applications
by Scott Swigart

Listing One

public class LineCountFactory
{
    public static ILineCountApplication Create(string appPath, bool visible)
    {
        Assembly assembly = Assembly.LoadFile(appPath);
        Type t = assembly.GetType("LineCount.Form1");
        Object instance = Activator.CreateInstance(t);
        ILineCountApplication app = (ILineCountApplication)instance;
        app.Start(visible);

        return app;
    }
}


Listing Two

public interface ILineCountApplication
{
    string SearchFolder {get; set;}
    void Start(bool visible);
    ICountStatistics[] Count();
    void Shutdown();
}


Listing Three

ILineCountApplication app = LineCountFactory.Create(
    Path.GetFullPath(@"..\..\..\LineCount\bin\debug\LineCount.exe"), true);
app.SearchFolder = Path.GetFullPath(@"..\..\");
foreach (ICountStatistics stat in app.Count())
{
    textBox1.Text += stat.LineCount + ":" + stat.FileName + "\r\n";
}
app.Shutdown();


1


