How do I go about defining a method, e.g. void doSuff() in an anonymous type? All documentation I can find uses only anonymous restricted basically to property lists. Can I even define a method in an anonymous type?
EDIT: OK, a quick look at very quick answers tells me this is impossible. Is there any way at all to construct a type dynamically and add an anonymous method to a delegate property on that type? I’m looking for a C# way to accomplish what the following JavaScript does:
...
person.getCreditLimit = function() { ... }
...
You absolutely can, with delegates:
I tried with a lambda in the
new { ... }and that didn’t work, but the above is totally fine.