Using part of a class in multiple projects

I have a set of methods that do some work on working with SQL joins, and so far they have been copied from project to project. But over time, the number of projects has grown, and I need to synchronize these methods if I find an error or you need to update it.

I managed to get it in the condition that the SQL access class is a partial class , one part is project-specific and contains wrappers for a specific database. The second part is general and contains methods that are used in all project-specific databases.

The problem is that now I will have a "utility" class, copied over 8 projects, with the same content, but in different namespaces. In C / C ++, this would be simple, because I would just include the contents of the file wherever needed. What to do in C #?

+3
source share
2 answers

Separate the class so that you can have a complete class containing all the common code in a common project. Use a common interface to represent bits of functionality that will be specific to a project, implement that interface in each project, and pass an instance of the interface to common code where necessary.

+4
source

As John says, building a library is a good idea.

, , , , , Visual Studio, .

, .

- .

, , - Mercurial scc . . , .

: VS Mercurial SCC ​​ .

+1

Source: https://habr.com/ru/post/1742411/


All Articles