Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a solution with several projects in it.

I would like to use a class declared in one of the projects in another one and therefore reference it from the project in which i wish to use it.

Ideally this class would be "Internal" however this prevents me from using it in the second project however if i make it public it will be visible outside of the solution.

Is there a way of declaring a class that will only be visible to projects within a solution and not external customers when it is distributed. Is this possible?

Thanks in advance

George
Posted

No. Consider this:

public: Access is not restricted.

protected: Access is limited to the containing class or types derived from the containing class.

Internal: Access is limited to the current assembly.

protected internal: Access is limited to the current assembly or types derived from the containing class.

private: Access is limited to the containing type.


Cheers
 
Share this answer
 
Comments
gwithey 19-Sep-12 4:46am    
Ah i thought this may be the case, i have read the documentation and tried to think of a solution however thought maybe somebody had stumbled across a way of achieving this even if it is a little far fetched. So a group of dlls are not able to share the class among themselves but not the code using them when distributed.
Mario Majčica 19-Sep-12 4:50am    
Unfortunately you are limited to the assembly. You may think of merging assemblies into one, but I'm not completely sure that it will work. Check this:
http://research.microsoft.com/en-us/people/mbarnett/ILMerge.aspx
gwithey 19-Sep-12 5:00am    
Ok thanks this could provide a possible solution, we already have a similar tool 'XenoCode' so could take this train of thought. I am just researching the issue at this stage before it is decided which route may be deemed the optimum direction for the project.
Mario Majčica 19-Sep-12 5:15am    
Try it and let us know. Good luck!
The Runtime.CompilerServices.InternalsVisibleToAttribute should do this.

See http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx[^] for details of use.

Alan.
 
Share this answer
 
Comments
gwithey 3-Oct-12 4:06am    
This was exactly what i was looking for and worked perfectly, thanks Alan =)
As of now, it is not possible via using scope keywords in C#. You can only implement a logic that would throw an exception when accessed from another assembly other than yours.

On a side note, let me tell you that even a class with private constructor can be constructed using Reflection.

This is my opinion on it. Let's see what others can propose to you :)

Regards
 
Share this answer
 
Comments
gwithey 19-Sep-12 4:51am    
Ok this makes sense, i suppose if i require security the exception route may be a good idea or something similar at least as not sure if the user of the dll's may be able to bury the exception. Thanks for the advice

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900