I want to call a method, which is in my program from my dll.
I now I can add an argument public void Bar(Action<string> print, string a)
. But is there other way to call it?
code in dll:
class Foo {
public void Bar(string a) {
//now I want to call method from program
Program.Print(a); // doesn't work
}
}
program:
class Program {
public static void Main(string[] args) {
var dll = Assembly.LoadFile(@"my dll");
foreach(Type type in dll.GetExportedTypes())
{
dynamic c = Activator.CreateInstance(type);
c.Bar(@"Hello");
}
Console.ReadLine();
}
public static void Print(string s) {
Console.WriteLine(s);
}
}
from (Loading DLLs at runtime in C#)
Is it possible?