-2

I recently asked a question about calling methods on generic types in C#: calling method in template in C#

The problem I have is that I cannot manipulate the types I want to create a generic function for. The types are SoapClients of a few WebServices that have the same methods. Is there any solution that would let me avoid copying the code?

Community
  • 1
  • 1
pt12lol
  • 2,332
  • 1
  • 22
  • 48
  • I really don't understand what are you saying. Also, there doesn't seem to any actual question in your post. – svick Jan 06 '13 at 15:49

1 Answers1

1

If I understand you correctly, you have several types that you cannot change, that don't share any interface but have some method in common. And you want to write a single method that invokes this common method for any of the types.

To do this, I think you have two options:

  1. Create a wrapper for each class, that does implement a common interface. You would then use that interface in your method and give it the wrapper as an argument.
  2. Use dynamic to invoke the method. Using dynamic, you don't have to implement any interface, but it also means you are losing all compile-time type checking (and autocompletion).
svick
  • 236,525
  • 50
  • 385
  • 514