I want to ask, does adding extension methods to datatypes works in the same way as Microsoft's methods or do they have any limitaion.
This is relevant to experienced programmers who had find some limitations while using them.
I want to ask, does adding extension methods to datatypes works in the same way as Microsoft's methods or do they have any limitaion.
This is relevant to experienced programmers who had find some limitations while using them.
The main difference from the user's perspective is that they are called on null references too.
What sort of limitations are you thinking of? I'm not particularly fond of the way they're discovered - and in particular, the way that if the extended type later gains a method with the same signature, that will silently be called with no warnings around the extension method at all.
There are some ways in which they don't work as well as one might like - for example, you can't write an extension method for a delegate type and call it directly on a lambda expression or anonymous method - but that's reasonable enough.
Beyond that, I'm not aware of significant limitations - and I certainly haven't seen any situations where Microsoft code has had special rules applied around extension methods.
Your last sentence makes it sound like you have seen some limitations - could you share them with us?
You can do anything in an extension method that you could do in a normal static method taking the object that you are extending as an argument. That is to say, you cannot suddenly break encapsulation or do other silly things with it.