I have a method in a class in another file that I want to take a dynamic method. I’m having some difficulty negotiating the setup. Any help would be appreciated, thanks!
for example…
File #1:
class DoSomethingClass
{
// define delegate
public delegate void DelegateMethod();
public void Main()
{
DelegateMethod d = Func1;
AnotherClass.CallsDynamicMethod("Test1", d);
d = Func2;
AnotherClass.CallsDynamicMethod("Test2", d);
// will this work?
// AnotherClass.CallsDynamicMethod("Test3", DoSomethingClass.instance.Func3);
}
// candidate methods for delegation
void Func1()
{ Console.WriteLine("calling Func1"); }
void Func2()
{ Console.WriteLine("calling Func2"); }
public void Func3()
{ Console.WriteLine("calling Func3"); }
}
File #2:
class AnotherClass
{
public static void CallsDynamicMethod(string words, DelegateMethod dynamicMethod)
{
Console.WriteLine("this is a " + words + " to call...");
dynamicMethod();
}
}
Hope this answers your problem