Encapsulating sub-namespace in C #

I have a class library project. In this project, I have several folders to separate the logic.

Suppose I have a DAL library and inside DAL I have IDAL , DALFactory and SQLServerDAL . <sh> Now, when I give the dAL dll to another programmer, he can use all subDlls. Suppose I do not want him to use SQLServerDal, but others. How can I encapsulate SQLServerDAL so that no one can understand that it exists.

Thank.
EDIT:
More simply:

using DAL; // it can be written
using DAL.IDAL; // it can be written
using DAL.DALFactory; // it can be written
using DAL.SQLServerDAL; // it dont want to allow anyone write that
+3
source share
4 answers

, . SQLServerDAL , , SQLServerDAL . SQLServerDAL DAL:

// what you have now:
namespace DAL.SQLServerDal
{
    public class A {}
    public class B {}
}

// in other assembly
using DAL.SQLServerDal ; // ok
new A () ; // ok

// with internal classes:
namespace DAL.SQLServerDal
{
    internal class A {}
    internal class B {}
}

// in other assembly
using DAL.SQLServerDal ; // ok
new A () ;               // error: A is inaccessible due to protection level

// what I propose:
namespace DAL
{
    internal static class SQLServerDal
    {
        public class A {}
        public class B {}
    }
}

// in other assembly
using DAL.SQLServerDal ; // error: namespace DAL.SQLServerDal does not exist

, , , , , .

+1

, , : -

SQLServerDAL . properties/assemblyinfo.cs DLL, SQLServerDAL:

using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Fully.Qualified.AssemblyName")]

, , , , DLL.

0

" DLL", ?

.

, DLL. , "sub DLL". , , DLL. , , . , , .

, internal. , . , internal .

0

, DLL, , . DLL " " .

- DLL libarary .

Stream stream = GetType().Assembly
               .GetManifestResourceStream("<<FULL QUALIFIED DLL NAME>>");
if (stream == null)
    throw new InvalidDataException("<<FULL QUALIFIED DLL NAME>> not found.");

byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, (int) stream.Length);

Assembly assembly = Assembly.Load(buffer);

, , , .

var sqlServerDAL = assembly.GetType("<<FULL QUALIFIED CLASS NAME>>");
var method = sqlServerDAL.GetMethod("<<METHOUD>>", BindingFlags.Public);

, , . DLL , .

0

All Articles