Solved

Reflection and looping through class fields

Posted on 2006-10-23
2
279 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

770 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