How do I dispatch to a method based on a parameter's runtime type in C# < 4?
问题 I have an object o which guaranteed at runtime to be one of three types A , B , or C , all of which implement a common interface I . I can control I , but not A , B , or C . (Thus I could use an empty marker interface, or somehow take advantage of the similarities in the types by using the interface, but I can't add new methods or change existing ones in the types.) I also have a series of methods MethodA , MethodB , and MethodC . The runtime type of o is looked up and is then used as a