I have this class:
''' <summary>
''' Utility class for managing ASP.NET session state.
''' </summary>
Public Class SessionHelper
''' <summary>
''' Private constructor to prevent instantiation since classes cannot be declared Shared in VB.
''' </summary>
Private Sub New()
End Sub
''' <summary>
''' Retrieves the current session state.
''' </summary>
''' <returns></returns>
Public Shared ReadOnly Property Session As HttpSessionState
Get
Return HttpContext.Current.Session
End Get
End Property
''' <summary>
''' Retrieves the current system connection string.
''' </summary>
''' <returns></returns>
Public Shared ReadOnly Property ConnectionString As String
Get
Dim raw As String = Session(SessionConstants.DotNetConnectionString)
If raw Is Nothing Then Return Nothing
Return raw.Replace(",", ";")
End Get
End Property
''' <summary>
''' Gets or sets a session variable.
''' </summary>
''' <param name="key">The key of the session variable.</param>
''' <returns>The value of the session variable.</returns>
Public Shared Property Item(ByVal key As String) As Object
Get
Return Session(key)
End Get
Set(value As Object)
Session(key) = value
End Set
End Property
End Class
And I get a compile error when I try to call the shared indexer:
SessionHelper("DotNetConnectionString")
Error BC30109 'SessionHelper' is a class type and cannot be used as an expression.
What am I doing wrong? Or does VB just not support shared indexers? I can call it explicitly as SessionHelper.Item("DotNetConnectionString")
but the indexer syntax is not working.