I dont like monkeypatching because in some cases its the reason for some problems and misunderstandings. Its the same why multiclass inheritiances are not available in languages like java or C#.
But what you can do is to consider if you should reuse a class and inherit it?
So what you can do in C# is to create a new class, extended from one of the .net classes. THe problem with the String class is not possible because it is sealed.
But you would be able to replace such a method with the "new" statement. In this way you can reuse it too.
But the main reason is maybe of the complexity to implement it. The way how the compiler works are different for oop languages as for prototype languages like JavaScript.
dynamic
keyword. – CodesInChaos Aug 28 '12 at 11:25DLR
was introduced in .NET 4, but it's intentionally limited to thedynamic
type to keep the existing type system strong. It's almost like asking why C# is not weakly typed. – Groo Aug 28 '12 at 11:27