In java, I believe you can attempt to call a method even though the compiler can't find the method in the object's known class. Basically, you could do something like this -
Object o;
o.SomeMethod();
The java compiler doesn't look to see if SomeMethod exists in o. It simply compiles the code and tries to find the method on the object at run-time. If it's not found, something like a MethodNotFoundException is thrown, and can be handled gracefully.
I want to do precisely the same thing in C# without using reflection. I think this type of behavior can be acheived in a roundabout way using the item of a foreach loop, but I want to be able to do it anywhere. Essentially, I want to be able to get this piece of code to compile -
try
{
Object o = new Object();
o.NonexistantMethod();
}
catch (Exception) { }
Can anyone help me out here