2

I have a C# class library that is going to be used in 2 different projects. One of them should access to all public classes and methods and the other one should only access to some of the classes and methods .

what is the best solution ?

nAviD
  • 2,784
  • 1
  • 33
  • 54

1 Answers1

5

I think your best bet would be InternalsVisibleTo attribute

Ordinarily, types and members with internal scope (in C#) and friend scope (in Visual Basic) are visible only in the assembly in which they are defined. The InternalsVisibleToAttribute attribute makes them also visible to the types in a specified assembly, which is known as a friend assembly. The attribute is applied at the assembly level. This means that it can be included at the beginning of a source code file, or it can be included in the AssemblyInfo file in a Visual Studio project

Of course this doesn't prevent people from calling your methods using reflection

I4V
  • 34,891
  • 6
  • 67
  • 79
  • Reflection respects accessibility levels. If this keyword works as its name suggests (by extending internal access to specific assemblies) then reflection still won't be able to call the internals from an assembly not specified by this attribute. – Matheus Rocha Feb 09 '20 at 06:08