Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using reflection to instantiate an object
Message
From
07/03/2011 14:58:30
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Using reflection to instantiate an object
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01502858
Message ID:
01502858
Views:
95
I am using reflection to instantiate an object. This works well and I have been using it since four years now.

Basically, I have this code:
        Dim loClass As Type = Nothing
        Dim loList As Framework.Framework.List = Nothing
        Dim loParameter(0) As Object

        loParameter(0) = oProcess

        Try
            loClass = Type.GetType("UniversalThread.ListSomething")
            loList = Activator.CreateInstance(loClass, loParameter)
        Catch loError As Exception
            oProcess.ErrorSetup(loError)
            Return False
        End Try
Then, from this point, I can access the list such as:
loList.ShowList()
But, the problem I can see is the following. At the time loList is created with the Activator, this does not expose the base class properties. So, in my case, I now need to check for a property of the base class before doing loList.ShowList(). Basically, I need to do this:
        Dim loClass As Type = Nothing
        Dim loList As Framework.Framework.List = Nothing
        Dim loParameter(0) As Object

        loParameter(0) = oProcess

        Try
            loClass = Type.GetType("UniversalThread.ListSomething")
            loList = Activator.CreateInstance(loClass, loParameter)
        Catch loError As Exception
            oProcess.ErrorSetup(loError)
            Return False
        End Try

        ' If the list requires administration
        If loList.lAdministrator Then
           ' Do something
        End If

        loList.ShowList()
Because of this type of approach, I cannot see the base class property values. In the particular list I am trying to access, lAdministrator is True. But, it cannot be seen at this point because of the way I have created the object. There might be something I am missing here but I am pretty sure this approach is causing this kind of reaction.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform