Limit access to a Class library in C#.NET

1.8k views Asked by At

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 ?

1

There are 1 answers

1
I4V On BEST ANSWER

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