Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Restricted access to a class
Message
From
25/05/2012 13:31:48
 
 
To
25/05/2012 12:38:00
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:
01544415
Views:
30
This message has been marked as a message which has helped to the initial question of the thread.
>>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.....
>
>Ok, this is very cool. This does it.
>
>However, it does not prevent the application to see it from the intellisense POV. Is there a way to block it completely from being visible at the application level?
>
>BTW, when trying to create an instance of it, at the application level, the proper message is then returned at the designer level:
>
>'Framework.Framework.Upload.Friend Sub New(toProcess As Framework.Framework.LXProcess)' is not accessible in this context because it is 'Friend'.
>
>But, it would be much better if there would be a possibility to hide it completely.

If you want to hide it completely then you must mark it private. In that case you would have to explicitly expose members to the outside world. ie. you end up with something like this:
Public Class Upload
	Friend Sub New()
	End Sub
	Friend Property SomeProperty() As String
		Get
			Return m_SomeProperty
		End Get
		Set
			m_SomeProperty = Value
		End Set
	End Property
	Private m_SomeProperty As String

	Friend Function DoSomething(s As String) As String
	End Function
End Class

Public Class PublicClass
	Private oUpload As New Upload()

	Public Property SomeProperty() As String
		Get
			Return oUpload.SomeProperty
		End Get
		Set
			oUpload.SomeProperty = value
		End Set
	End Property

	Public Function DoSomething(s As String) As String
		Return oUpload.DoSomething(s)
	End Function
End Class
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform