I would like to be able to determine the type of an object and then cast that object into what it should be. I'll do my best to explain. The code below DOES NOT work, but it shows what I am looking to achieve. I need to return the size of an unknown object type; could be a button, a panel, form, etc.
public static void Draw(object AnimateObject) { try { // Set the starting coordinants for our graphics drawing int y = 0; int x = 0; // Set the end coordinants for our graphics drawing int width = AnimateObject.Size.Width; int height = AnimateObject.Size.Height; // More graphics related stuff here... } } Normally I could just cast the object into what it should be and be done with it, but once the 'Unknown object' part came up, I've somewhat hit a dead end. I'm sure I could overload the thing a million times and make it find the right type, but I'm hoping there is a more sensible way to do it.
dynamicnotobject.Size? That is what polymorphism is all about.dynamic. It will move all checkes from compile time to runtime. Or find a common type which all other derives from (or interface then implement) and create generic method.