5 ms·
Your solution is at least as ugly as the one mentioned in the article. The problem is that void can't be used as a regular type identifier. In a lot of langag
by raphaelj 13y ago
Your solution is at least as ugly as the one mentioned in the article.
The problem is that void can't be used as a regular type identifier.
In a lot of langages (like Python, Haskell, F#, ...) there is a regular type for void. This type is often implemented as such :
sealed struct Void {
}
Then you can define Action<...> just as Func<Void, ...>.
As the compiler is smart enough to see there is only one kind of Void value, it can be entierly removed from the generated code and thus doesn't make your code slower.
- V-2 13y agoAnd quite what's so ugly about it? It's hackish, but once you create these overloads, you don't need to worry about it anymore and you can call the method just as if Func<T> could be casted to Action. I don't think it can even be compared to the one suggested in the article, since it does not require "creating a separate overload with an identical implementation" (!!!), potentially copy-pasting hundreds of lines of code if the method in question was indeed "more complicated". This is ridiculous and the fact the author couldn't think of a workaround that didn't involve it baffles me.