Forum  Commercial Foru...  Commercial Foru...  Reflection Feedback
Previous Previous
 
Next Next
New Post 5/25/2009 3:52 PM
Resolved
  derekmhart@yahoo.com
685 posts
1st Level Poster


Reflection Feedback 
Modified By derekmhart@yahoo.com  on 5/25/2009 7:35:59 PM)

 

Wanting to get some feedback on reflection, if I am doing things in a best practices way. My goal is to let a user create a new project, create forms or usercontrols, and load them dynamically at runtime. One of my concerns is loading the object as an object, and then determining what type it is, a form or a usercontrol. Seems to work fast on my local machine, but if hundreds of these are being loaded, will it be a robust way to do this?

    Public Enum DynamicObjectType
        Form
        UserControl
    End Enum

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim DOT As New DynamicObjectType
        Dim currentDomain As AppDomain = AppDomain.CurrentDomain
        'Provide the current application domain evidence for the assembly.
        Dim asEvidence As Evidence = currentDomain.Evidence
        'If we don't do this, it won't be able to find the assembly of our custom .dll  library
        'Load the assembly from the application directory using a simple name.
        'Create the assembly
        currentDomain.Load("AnotherBigOne", asEvidence)
        'Get the form

        Dim daForm As Object = CreateObject("AnotherBigOne", "AnotherBigOne.Form1")

        If TypeOf daForm Is Form Then
            DOT = DynamicObjectType.Form
        ElseIf TypeOf daForm Is UserControl Then
            DOT = DynamicObjectType.UserControl
        End If

        For Each ctl As Control In daForm.Controls
            If ctl.Name = "TextBox1" Then
                DirectCast(ctl, VaultControls.TextBox).Text = DirectCast(ctl, VaultControls.TextBox).Calculation
            End If
        Next

        Select Case DOT
            Case DynamicObjectType.Form
                daForm.ShowDialog()
            Case DynamicObjectType.UserControl
                Me.Controls.Add(daForm)
                daForm.Parent = PanelMain
                daForm.Dock = DockStyle.Fill
                daForm.BringToFront()
        End Select
    End Sub

    Private Function CreateObject(ByVal AssemblyName As String, ByVal TypeName As String) As Object
        'Make an array for the list of assemblies.
        Dim assems As [Assembly]() = AppDomain.CurrentDomain.GetAssemblies()
        'Search for the assembly and return the object specified
        For Each asm As System.Reflection.Assembly In assems
            Debug.WriteLine(asm.FullName)
            If asm.FullName.StartsWith(AssemblyName & ",") Then
                Return asm.CreateInstance(TypeName)
            End If
        Next asm
    End Function
 

 
New Post 5/26/2009 5:49 AM
  ori.cohen
4383 posts
1st Level Poster




Re: Reflection Feedback 
Modified By ori.cohen  on 5/26/2009 7:49:26 AM)

Hello Derek,

It would be very helpful if you could please describe to me what is it that you are trying to accomplish in the UI flow, and what is the scenario you are constructing in your application. It would greatly help me to see the bigger picture. I would be able to either open an issue for required changes in our framework, or suggest to you the best and most robust and yet efficient implementation available to achieve what you want in your VWG application.

Regards,

Ori Cohen
Support Manager, the Visual WebGui team

 
New Post 5/26/2009 6:01 PM
  derekmhart@yahoo.com
685 posts
1st Level Poster


Re: Reflection Feedback 

It all comes down to this:

       Select Case DOT
            Case DynamicObjectType.Form
                daForm.ShowDialog()
            Case DynamicObjectType.UserControl
                Me.Controls.Add(daForm)
                daForm.Parent = PanelMain
                daForm.Dock = DockStyle.Fill
                daForm.BringToFront()
        End Select

I can have developers build a new VWG project, build either forms or usercontrols, and compile the application. Then the DLL for this project can be copied and pasted into the bin directory of the main application on the live server. I can then dynamically read this DLL, getting the name of the DLL and the forms to call from a SQL database. Just want to make sure there are no major problems here.

 
New Post 5/27/2009 1:45 PM
  palli
11189 posts
1st Level Poster




Re: Reflection Feedback 

Hi Derek,

I think it's best for everyone if we wait for Ori's response to these questions. I will make sure he gets notified and he will respond here on this thread.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 5/28/2009 2:57 AM
Accepted Answer 
  ori.cohen
4383 posts
1st Level Poster




Re: Reflection Feedback 
Modified By ori.cohen  on 5/28/2009 4:57:32 AM)

Hello Derek,

there is absolutely no problem loading a Form using reflection by namespace+name.

Here is a code exapmle:
Form objSomeForm = Activator.CreateInstance(Assembly.GetExecutingAssembly().GetModules()[0].GetType("WebGUIApplication1.Form1"));

Once you get the Form object, you could know the specific Type of the Form and use it as you like.
the "WebGUIApplication1.Form1" is just an example. You should replace this part with a string you get from the DB. I just wanted to provide it to you, so you would know the specific Format required.

Please reply if there is anything else I can help you with on this subject.

Regards,

Ori Cohen
Support Manager, the Visual WebGui team

 
Previous Previous
 
Next Next
  Forum  Commercial Foru...  Commercial Foru...  Reflection Feedback
CompanionKit Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS