I dynamically load an assembly as:
var assembly = Assembly.LoadFile("PathOFMyDll");
anyways that assembly has the static method Filter inside the class DynamicClass. So once I have that assembly I exececute that method as:
var filter = assembly.GetType("DyamicClass").GetMethod("Filter");
// that method accepts a object as parameter
filter.Invoke(null, new object[] { "test" });
Now my question is:
I have the delegate delegate bool FilterDelegate(object item); why it is not possible make a delegate of that type point to that method in order to have:
FilterDelegate myPointerToMethodFilter = (FilterDelegate)assembly.GetType("DyamicClass").GetMethod("Filter");
bool result = myPointerToMethodFilter("test");
note the compiler only complains when trying to compile. I do not get any syntax errors.
It is possible to create a delegate from a
MethodInfoobject, but casting is not sufficient.Instead, use
Delegate.CreateDelegate():