Solved

Reflection and looping through class fields

Posted on 2006-10-23
2
276 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
2 Comments
 
LVL 5

Accepted Solution

by:
xersoft earned 500 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now