Solved

Reflection and looping through class fields

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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