Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Restricted access to a class
Message
From
25/05/2012 03:06:20
 
 
To
24/05/2012 17:39:45
General information
Forum:
ASP.NET
Category:
Class design
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01544358
Message ID:
01544369
Views:
42
This message has been marked as the solution to the initial question of the thread.
>I have a class which I only want to expose access from its own DLL. However, another class from this DLL is creating an instance of that class. Then, from that instance, that class exposes a method or a property of the class that should not be available outside the DLL.
>
>So, lets say a class is creating an instance of the other class as:
>
>
>        Public oUpload As Framework.Upload = New Framework.Upload(oProcess)
>
>
>And, this class can expose oUpload to the application as it is public. So, the application can then do things like this:
>
>
>        ' Assign the Excel file
>        loImport.cSource = oUpload.cFile
>
>
>So, at this point, the Upload class is defined Public and the other class creating an instance of it is declaring oUpload as Public. Thus, the application can gain access to the Upload methods and properties which are public.
>
>Having said that, it means the application can create an instance of the Upload class. This is what I do not want. If I put Friend for the class declaration, this will allow the other class to create an instance of it but will not allow the other class to declare oUpload as Public.
>
>Is there a way to negotiate with that need?

If your only concern is to prevent instantiation of the class outside of its own assembly then mark the constructor as Friend:
Namespace Framework
	Public Class Upload
		Friend Sub New()
		End Sub
	End Class

	Public Class PublicClass
		Public oUpload As New Upload()
	End Class
End Namespace
If there are members of Upload that you also do not want to expose outside of the assembly then just mark those Friend as well.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform