<p>I have seen these being used every which way, and have been accused of using them the wrong way (though in that case, I was using them that way to demonstrate a <a href="http://blog.gadodia.net/extension-methods-in-vbnet-and-c/" rel="noreferrer">point</a>).</p>

<p>So, what do you think are the best practices for employing Extension Methods?</p>

<p>Should development teams create a library of extension methods and deploy them across various projects?</p>

<p>Should there be a collection of common extension methods in the form of an open source project?</p>

<p><em>Update: have decided to create an organization wide extension methods library</em></p>

[{'answer_id': 3152, 'author': 'Yaakov Ellis', 'author_id': 51, 'author_profile': 'https://Stackoverflow.com/users/51', 'pm_score': 2, 'selected': False, 'text': '<p>I think that it depends on what purpose the Extension methods serve.</p>\n\n<ul>\n<li>Extension methods that relate to specific business needs of a project (whether they are connected to basic data types or custom objects) should not be included in a library that would be distributed across multiple projects.</li>\n<li>Extension methods that relate to basic data types (int, string, etc) or generics that have a wider application could be packaged and distributed across projects.</li>\n</ul>\n\n<p>Take care not to globally include Extension methods that have little application, as they just clog up intellisense and can lead to confusion and/or misuse.</p>\n'}, {'answer_id': 3155, 'author': 'tags2k', 'author_id': 192, 'author_profile': 'https://Stackoverflow.com/users/192', 'pm_score': 2, 'selected': False, 'text': "<p>I've been including my extension methods in with my Core libraries in the Utils class because people who are working with my framework are likely to find the methods useful, but for mass deployment where the end developer might have a choice of extension method libraries, I would advise putting all of your extensions into their own namespace, even their own project file, so that people can choose to add a reference or a using statement or simply where required, like so:</p>\n\n<pre><code>Core.Extensions.Base64Encode(str);\n</code></pre>\n\n<p>My Utils class is my bestest friend in the whole world, it was before extension methods came along and they have only helped to strengthen our relationship.  The biggest rule I would go by is to give people choice over what extension framework they are using where possible.</p>\n"}, {'answer_id': 4623, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 2, 'selected': False, 'text': '<p>you might want to take a look at <a href="http://www.codeplex.com/nxl" rel="nofollow noreferrer">http://www.codeplex.com/nxl</a> and <a href="http://www.codeplex.com/umbrella" rel="nofollow noreferrer">http://www.codeplex.com/umbrella</a> which are both extension method libraries. I personally haven\'t had a look at the source code but I\'m sure the guys there would be able to give you some good pointers.</p>\n'}, {'answer_id': 5770, 'author': 'Chris Hanson', 'author_id': 714, 'author_profile': 'https://Stackoverflow.com/users/714', 'pm_score': 2, 'selected': False, 'text': '<p>The Objective-C language has had "Categories" since the early 1990s; these are essentially the same thing as .NET Extension Methods.  When looking for best practices you might want to see what rules of thumb Objective-C (Cocoa &amp; NeXT) developers have come up with around them.</p>\n\n<p><a href="http://inessential.com/" rel="nofollow noreferrer">Brent Simmons</a> (the author of the NetNewsWire RSS reader for Mac OS X and iPhone) just posted today about his <a href="http://inessential.com/?comments=1&amp;postid=3518" rel="nofollow noreferrer">new style rules for the use of categories</a> and there\'s been a bit of <a href="http://evand.org/2008/08/07/reuse-vs-use-once/" rel="nofollow noreferrer">discussion in the Cocoa community</a> around that post.</p>\n'}, {'answer_id': 13251, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 3, 'selected': False, 'text': '<p>The upcoming release of the Framework Design Guidelines, 2nd Edition will have some guidance for implementing extension methods, but in general:</p>\n\n<p>You should only define extension methods "where they make semantic sense" and are providing helper functionality relevant to every implementation.</p>\n\n<p>You also should avoid extending System.Object as not all .NET languages will be able to call the extension method as an extension. (VB.NET for instance would need to call it as a regular static method on the static extension class.)</p>\n\n<p>Don\'t define an extension method in the same namespace as the extended type unless you\'re extending an interface.</p>\n\n<p>Don\'t define an extension method with the same signature as a "real" method since it will never be called.</p>\n'}, {'answer_id': 17662936, 'author': 'deegee', 'author_id': 1655625, 'author_profile': 'https://Stackoverflow.com/users/1655625', 'pm_score': 1, 'selected': False, 'text': '<p>When I first found out about Extensions I really overused and abused them.</p>\n\n<p>For the most part I have started to get away from using any Extension Methods for a number of reasons.</p>\n\n<p>Some of the reasons I stopped using them are noted in Scott\'s blog link above, such as "Think twice before extending types you don\'t own".  If you have no control over the source for the types you are extending, you may encounter issues/collisions in the future if the source type has some additions/changes, such as moving your project to a newer .NET version.  If the newer .NET version includes a method on the type of the same name as your extension, someone is going to get clobbered.</p>\n\n<p>The main reason why I stopped using Extension Methods is that you can\'t quickly tell from reading the code where the source of the method is and who "owns" it.</p>\n\n<p>When just reading through the code you can\'t tell whether the method is an extension or just a standard NET API method on the type.</p>\n\n<p>The intellisense menu can get really messy really fast.</p>\n'}]
['https://Stackoverflow.com/questions/3147', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/380/']