T
T
tikks2016-10-20 12:29:03
C++ / C#
tikks, 2016-10-20 12:29:03

What is a good alternative for type-switch to call different methods in a generic method, depending on the class?

Good afternoon!
I'm looking for some pattern that would be a good alternative to type-switch.
There is a class that is a project (third-party COM wrapper). The project has entities of different types, their wrapper classes are inherited from the same class, and in many ways they can be worked with in the same way. I also want to get all entities of the same type from the project in the same way with one genetic method. The problem is that COM uses different methods to get all entities of different types. Accordingly, a generic method for obtaining all entities of a certain type must be able to call different methods depending on the entity type.
Maybe there is some decent alternative for type-switch in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2016-10-20
@tikks

Dictionary to use a dictionary, add a type and a lambda, a delegate or a reference to a method, and that's it, then just get it from the dictionary of the Action type and call it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question