That is why he is known, this question is mostly academic, although I tried to use this concept in the real world. I understand that the example is contrived, but I believe that the concept is valid.
I want to write some free code, for example:
copy(my_first_file).to(my_second_file)
Short, easy to read and understand, completely legal. Therefore, I define my copy method as follows:
Private Function copy(FilePath as String) As Object Return New With {.to = New Action(Of String)(Function(x) my_real_copy_method(FilePath,x))} End Function
I understand that I cannot force an anonymous type to a specific type (for example, implement an interface or some other class), and I do not want the overhead to define a specific class to match my desired free name with the name of the actual method. So I was able to make the code like this:
copy(my_first_file).to.Invoke(my_second_file)
So there is no IntelliSense or type, and I have to enable Invoke to run this method. How can I get more type safety and exclude the Invoke method, under these restrictions:
- Anonymous type returned from method
- No additional classes or interfaces.
- Preferably, I do not want to pass another parameter to the copy () method, which tells which type will be returned if the copy does not become a universal method (but I think it means defining a different class / interface, I want to do it)
I know that sounds pretty demanding, feel free to call "Bull" if it's hard for me!
Thanks in advance.
source share