?
Solved

Reflection and looping through class fields

Posted on 2006-10-23
2
Medium Priority
?
285 Views
Last Modified: 2008-01-09
Hi Guys,

Im new to VB.Net and Ive got a little problem in that Im attempting to load a class from a .dll and then populate the fields in the class that I instantiate.
The overall aim is that I have a .dll which can be changed by a third party, from which Im creating a GUI made up of textboxes, labels, combos. From there the user inputs the data then we need to populate the class, convert it to xml then fire it to the third party.


So far Ive got to the stage where Ive looped through the class to get the name of the fields using
        Dim myassembly As Reflection.Assembly
        Dim looptype As Type
        Dim types() As Type
     
       myassembly = Reflection.Assembly.LoadFrom("c:\test.dll")
       types = myassembly.GetTypes

       For Each looptype In types
       ........

and created the form in a rough way using the name of the field as the name of the textboxes

Now what Im atempting to do is reference the fields of the class that Ive instantiated using

        Dim fillClass As Object
        Dim myassembly As Reflection.Assembly
        myassembly = Reflection.Assembly.LoadFrom("c:\test.dll")
        fillClass = myassembly.CreateInstance("test.testclass")

So how do I either loop thorugh the collection of textboxes and using their name assign the value into the class field of the same name, or loop through the class fields and assign the value from the textbox of the same name?

Any help would be great, or any pointers on where to look

cheers
Ben


0
Comment
Question by:BBaron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
xersoft earned 2000 total points
ID: 17789109
Take a look at this project: https://filedb.experts-exchange.com/incoming/ee-stuff/1198-ReflectionTest.zip 

Let me know if it answers your question.

It shows an example of what I think you are trying to do.
0
 

Author Comment

by:BBaron
ID: 17789296
Hi and thanx, thats pretty much exactly what I was after, all I need to do it change it so it loads from a dll and should get me well on my way. I wouldnt have got that in a month of Sundays, thanx again

Cheers
Ben
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question