M
Martin Carolan
Hi there,
I have an interface (called AuthenticationInterface) shown below:
Public Interface AuthenticationInterface
Function IsLoggedIn() As Boolean
Function Authenticate(ByVal User As LinkDirectoryUser) As Boolean
Function GetCurrentUser() As LinkDirectoryUser
Function IsUserSuspended(ByVal User As LinkDirectoryUser) As
Boolean
Function GetAllRoles() As String()
Sub Register(ByVal User As LinkDirectoryUser)
Sub Logout()
Sub DeleteUser(ByVal User As LinkDirectoryUser)
Sub SuspendUser(ByVal User As LinkDirectoryUser)
Sub UpdateUser(ByVal User As LinkDirectoryUser)
End Interface
And I use the following code to load a type that implements that
interface based on the value of the web.config file:
Public Function Current() As Object
Dim asm As String = HttpContext.Current.Server.MapPath("bin\"
& ConfigurationSettings.AppSettings("AuthenticationProvider"))
Dim objDll As [Assembly] = [Assembly].LoadFrom(asm)
For Each t As Type In objDll.GetTypes
If t.IsPublic Then
If Not ((t.Attributes And TypeAttributes.Abstract) =
TypeAttributes.Abstract) Then
Dim objInterface As Type =
t.GetInterface("AuthenticationInterface", True)
If Not objInterface Is Nothing Then
Dim objPlugin As Object =
objDll.CreateInstance(t.FullName)
Return objPlugin
End If
End If
End If
Next
End Function
As you can see this returns an object, this is because I get casting
errors when trying to convert the object to a AuthenticationInterface
(but I can still use the object perfectly), my question is how can I
convert the object loaded to a AuthenticationInterface without causing
a cast error?
Thanks loads, Martin.
I have an interface (called AuthenticationInterface) shown below:
Public Interface AuthenticationInterface
Function IsLoggedIn() As Boolean
Function Authenticate(ByVal User As LinkDirectoryUser) As Boolean
Function GetCurrentUser() As LinkDirectoryUser
Function IsUserSuspended(ByVal User As LinkDirectoryUser) As
Boolean
Function GetAllRoles() As String()
Sub Register(ByVal User As LinkDirectoryUser)
Sub Logout()
Sub DeleteUser(ByVal User As LinkDirectoryUser)
Sub SuspendUser(ByVal User As LinkDirectoryUser)
Sub UpdateUser(ByVal User As LinkDirectoryUser)
End Interface
And I use the following code to load a type that implements that
interface based on the value of the web.config file:
Public Function Current() As Object
Dim asm As String = HttpContext.Current.Server.MapPath("bin\"
& ConfigurationSettings.AppSettings("AuthenticationProvider"))
Dim objDll As [Assembly] = [Assembly].LoadFrom(asm)
For Each t As Type In objDll.GetTypes
If t.IsPublic Then
If Not ((t.Attributes And TypeAttributes.Abstract) =
TypeAttributes.Abstract) Then
Dim objInterface As Type =
t.GetInterface("AuthenticationInterface", True)
If Not objInterface Is Nothing Then
Dim objPlugin As Object =
objDll.CreateInstance(t.FullName)
Return objPlugin
End If
End If
End If
Next
End Function
As you can see this returns an object, this is because I get casting
errors when trying to convert the object to a AuthenticationInterface
(but I can still use the object perfectly), my question is how can I
convert the object loaded to a AuthenticationInterface without causing
a cast error?
Thanks loads, Martin.