How to use extension methods in many projects.

I am learning an extension method, a very handy feature that can save hours of coding, provides reuse. what I do now, days, every day I create 10 extension methods that are useful in a daily scenario. but I don’t get how to use these extension methods, every time we need to add a dll and reference it. or is there some smart way where we can use.

Let's pretend that

public static bool isValidMail(this string str) { Regex reg = new Regex(@"^[\w-\.] +@ ([\w-]+\.)+[\w-]{2,4}$"); return reg.IsMatch(str); } 

if I created 100 extension methods like this, then for each project I will need to refer to this static class DLL. since I work with multiprocessor projects. Is there a way that we can put these extension methods in a centralized location or some kind of build cache where we can easily add a using statement and access all the static methods.

can we do this?

  • whenever we create a new project, VS automatically adds the extension methods that we created, so that in the evey project we can access it. instead of adding dll every time

  • I want to know how you do it. I hope no one votes, just curious how to implement extension methods

+7
source share
2 answers

It looks like you should have one project containing related extension methods - and then yes, you need to add a link to this project from each project that it needs. This is a one-time cost. You can put it in the GAC, but I personally wouldn’t do it - just consider it as another class library that you need to depend on, like any other.

+8
source
  • You can modify the VS 2010 project templates to automatically include the "Framework" DLL. visual studio templates

  • I just keep a common repository of various shared DLLs and reference the ones I need, this is also in SVN. Then I have specific snippets for each Framework I have created to make it easier to insert frequently used code.

0
source

All Articles