resourcesys
asked on
Make friend class visible to another assembly
Hi all,
I have written a test class in an assembly. It is a friend class and I would like it to be visible to another assembly. The class is as follows:
Imports System.Runtime.CompilerSer vices
<Assembly: InternalsVisibleTo("T01_BL L")>
Friend Class Class1
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class
the problem I have is that when I add another class to the assembly, it is also visible to the other assembly.
Is there a way to get the single class to be visible and not all classes of the assembly?
Any help is greatly appreciated.
Thanks.
I have written a test class in an assembly. It is a friend class and I would like it to be visible to another assembly. The class is as follows:
Imports System.Runtime.CompilerSer
<Assembly: InternalsVisibleTo("T01_BL
Friend Class Class1
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class
the problem I have is that when I add another class to the assembly, it is also visible to the other assembly.
Is there a way to get the single class to be visible and not all classes of the assembly?
Any help is greatly appreciated.
Thanks.
Use the keywords above per class accordingly:
Public Class Class 1{}
Private Class Class 2{}
Regards
Public Class Class 1{}
Private Class Class 2{}
Regards
Sorry, just re-read:
If you want to restrict the view to another asembly only, there are a few alternatives:
. set the other class members as private... but that means they are also private to each other within the same assembly
. the assembly attribute InternalsVisibleToAttribut e can be used multiple times, hence, using a 3 assembly structure, you could have: AssemblyA, AssemblyB and AssemblyC
AssemblyB would include the common classes (as in your example above), and with the InternalsVisibleToAttribut e set twice to allow visibility to AssemblyA and AssemblyC (where you'd put the rest of your classes).
Hope this helps.
If you want to restrict the view to another asembly only, there are a few alternatives:
. set the other class members as private... but that means they are also private to each other within the same assembly
. the assembly attribute InternalsVisibleToAttribut
AssemblyB would include the common classes (as in your example above), and with the InternalsVisibleToAttribut
Hope this helps.
ASKER
Hi pedros7,
Thank you for your responses.
The sturcture of the test application i wanted to develop would be a data access layer assembly (DAL), a business logic layer assembly (BLL), and a website.
The website would interect with the BLL and the BLL would interact with the DAL.
I don't think I'm going to be able to achieve this, although I could have a seperate assembly just for the database object, that way, the database could be seen by the DAL, the DAL could be seen by the BLL, and the BLL could be seen by the website.
I think that would would work.
I wanted the DAL to be visible to BLL only, InternalsVisibleTo would do this, but I wanted a database class in the DAL to be visible only within the DAL.
Thank you for your responses.
The sturcture of the test application i wanted to develop would be a data access layer assembly (DAL), a business logic layer assembly (BLL), and a website.
The website would interect with the BLL and the BLL would interact with the DAL.
I don't think I'm going to be able to achieve this, although I could have a seperate assembly just for the database object, that way, the database could be seen by the DAL, the DAL could be seen by the BLL, and the BLL could be seen by the website.
I think that would would work.
I wanted the DAL to be visible to BLL only, InternalsVisibleTo would do this, but I wanted a database class in the DAL to be visible only within the DAL.
ASKER
Sorry, the last message should read as:
Hi pedros7,
Thank you for your responses.
The sturcture of the test application i wanted to develop would be a data access layer assembly (DAL), a business logic layer assembly (BLL), and a website.
The website would interect with the BLL and the BLL would interact with the DAL.
I wanted the DAL to be visible to BLL only, InternalsVisibleTo would do this, but I wanted a database class in the DAL to be visible only within the DAL.
I don't think I'm going to be able to achieve this, although I could have a seperate assembly just for the database object, that way, the database could be seen by the DAL, the DAL could be seen by the BLL, and the BLL could be seen by the website.
I think that would would work.
Hi pedros7,
Thank you for your responses.
The sturcture of the test application i wanted to develop would be a data access layer assembly (DAL), a business logic layer assembly (BLL), and a website.
The website would interect with the BLL and the BLL would interact with the DAL.
I wanted the DAL to be visible to BLL only, InternalsVisibleTo would do this, but I wanted a database class in the DAL to be visible only within the DAL.
I don't think I'm going to be able to achieve this, although I could have a seperate assembly just for the database object, that way, the database could be seen by the DAL, the DAL could be seen by the BLL, and the BLL could be seen by the website.
I think that would would work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Question answered
ASKER
Thanks pedros7.
That should work. The keywords Private, Friend and Public are the following:
Private – within the same module, class, or structure.
Friend – within the same assembly.
Public – anywhere in the same project, from other projects that reference the project, and from any assembly built from the project. In other words, any code that can find it.
Regards