Solved

Reflection and looping through class fields

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 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