C # allows you to define an implicit cast to a delegate type:
class myclass { public static implicit operator Func<String, int>(myclass x) { return s => 5; } public static implicit operator myclass(Func<String, int> f) { return new myclass(); } }
But, unfortunately, we cannot use this to make the object look like a function:
var xx = new myclass(); int j = xx("foo");
Is there a good way to force an object of one class to accept function style parameters (arguments) directly on its base instance? Kind of like an indexer, but with parentheses instead of square brackets?
source share