Parser
Key
_dict
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Collections Imports System.Configuration Imports System.Collections.Generic Public Class SessionVar Public Enum Key AppVerId LastAreaCode End Enum Private Shared _dict As Dictionary(Of Key, String) '---------------------------------------------------------------------------------------------- Shared Sub New() _dict = New Dictionary(Of Key, String)() _dict.Add(Key.AppVerId, "AppVerId") _dict.Add(Key.LastAreaCode, "LastAreaCode") End Sub '---------------------------------------------------------------------------------------------- Public Shared Function GetKey(ByVal key As Key) As String Return _dict(key) End Function '---------------------------------------------------------------------------------------------- Public Shared Function GetValue(ByVal key As Key, Optional ByVal defaultValue As String = "") _ As String Dim s As String = HttpContext.Current.Session(_dict(key)) If s Is Nothing Then s = "" End If If s.Length = 0 Then s = defaultValue End If Return s End Function '---------------------------------------------------------------------------------------------- Public Shared Function TryGetValue(Of T)(ByVal key As Key, ByRef value As T) As Boolean Return Parser(Of T).TryParse(GetValue(key), value) End Function '---------------------------------------------------------------------------------------------- Public Shared WriteOnly Property [Set](ByVal key As Key) As String Set(ByVal value As String) Try _dict(key) = value Catch ex As Exception Throw ex End Try End Set End Property End Class
TODO
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.