Extension methods was introduced some time back with C#3.0 .The feature is great we can attach one more function to the existing classes and can call those methods with the object of those classes itself.It is very helpful for architects to write all the required methods and attach with the existing classes as well.
We all might have surprised by seeing so many methods suddenly in our favorite IEnumerable derived classes such as List and observable collection when the linq is introduced.Did they wrote all these methods inside the List class? absolutely not.Instead they wrote extension methods for IEnumerable and from the user point of view they looks like normal methods because the methods can be invoked just by using the objects.
I was looking for some uses of the extension methods like this.The option is to replace all most all the helper classes by extension methods. While looking through the helper classes I struck around the reflection helper. The code was written to get the value of property using reflection.If the developer is familiar with the code base he probably knows that there is a helper library and can use it.But what about a fresher.He will surely struck on this and may think about changing the design.If he is coming from the true object oriented world where there is no chance to invoke private properties he is done. The GetProperty and SetProperty really comes helpful here.
Don’t feel so much complicated .Its so simple .Write 2 extension methods which internally gets and sets the value of properties by getting the name of property in string.Now it comes very easy to the end developer as the method will be shown when they type the magic key dot(.)
Before using extension methods make sure that the assembly is referred and using the namespace.