Created
December 17, 2012 10:30
-
-
Save digiguru/4317308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Module SessionExtensions | |
<Runtime.CompilerServices.Extension()> | |
Public Function TryGetValue(session As System.Web.SessionState.HttpSessionState, | |
sessionItemName As String, | |
ByRef result As Object) As Boolean | |
If session Is Nothing Then | |
Throw New ArgumentNullException("Session", "Session is nothing.") | |
End If | |
If String.IsNullOrEmpty(sessionItemName) Then | |
Throw New ArgumentException("SessionItemName is nothing or empty.", "SessionItemName") | |
End If | |
result = session(sessionItemName) | |
Return result IsNot Nothing | |
End Function | |
<Extension()> | |
Public Function TryConvertValueOf(Of T As {Class})(ByVal sess As HttpSessionState, | |
ByVal param As String, | |
ByRef output As T) As Boolean | |
Dim obj As Object = sess(param) | |
If TypeOf obj Is T Then | |
output = DirectCast(obj, T) | |
Return output IsNot Nothing | |
End If | |
Return False | |
End Function | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment