Question Matching Fields Between Objects

Joined
Jun 2, 2011
Messages
16
Programming Experience
3-5
I am using VB.net to send XML between systems. I am using web services, and XSDs to make the classes, and that is going fine. I have one class for the source data, and many classes for where this data is destined to go.

So I have a DB object with Property firstName and I have to put that in Destination Object1 with a Property of FirstName, Object2 with a Property fName, Object3 has a Name Object so firstName goes in Name.First. And so forth.

What is the proper way to approach this? Does VB or VS (I am using VS2010) provide a sensible way to deal with this common problem? Can someone please guide me in the right direction. I am happy to do my own research and study, but I really don't know where to start here. I assume this is a common problem and there is a concept in the Computer Sciences that relates to it, but I don't know what it is....
 
Last edited:
Er .... common? Not really. Essentially what you're asking (at least as you have stated it) is, is there a way for the computer to guess that DB.firstname and Object2.fName are the same thing so that if I randomly broadcast DB.firstName all the destination objects will psychically link up and say "Ah, I know where that goes"? Has anything you've ever done in programming suggested that this is the way things work? What if all the property names were in fact identical? Would it make any difference?
 
Er .... common? Not really. Essentially what you're asking (at least as you have stated it) is, is there a way for the computer to guess that DB.firstname and Object2.fName are the same thing so that if I randomly broadcast DB.firstName all the destination objects will psychically link up and say "Ah, I know where that goes"? Has anything you've ever done in programming suggested that this is the way things work? What if all the property names were in fact identical? Would it make any difference?

Uh, well that is not what I am trying to ask at all, and maybe I should have explained more.

Currently, I am dealing with this with text files that contain corresponding Property Names and using routines to parse the text in the files. I have all these text files all over the place, and all these routines to parse the text. I am actually using reflection to populate the objects with data. It's a mess and cumbersome. Reflection relies on Late Binding (I think) and this creates all kinds of problems with catching errors and logging things. It's not the right way to do this stuff (though it does work.. for now).

However, I suspect that there is a more organized way to approach this. Mapping a property in an object to a property in another object is so common, VB or VS must have tools to help do it. I am reaching out to real VB programmers to help, please, show this self-taught noob how to approach this problem properly.
 
Oh boy!! Well the first step is to get all the data in one place and stop associating it with property names altogether. You need to separate yourself from the notion that these things belong together in some way. So you just need one list of first names, say, to populate all the objects whatever the property names may be.
 
There shouldn't even be any of these objects. Data should be in one place only, everywhere else should be taking it directly from the source... The datasource.

Use a dataset or some other appropriate data object for your use, but do NOT copy the data, or keep it in multiple places. That's a recipe for disaster. A sample of the data and a definition of the relationship between those objects for a single record would help narrow it down for you.
 
The Source of the Date comes as a SOAP Message, but I handle the date with a class VS made with the WSDL. For all is see, it is a regular VB Object with Properties like FirstName, Address, etc. A pretty standard Database Object. I never see the SOAP Message, and actually use Fiddler read it, because I cannot find a way to to read the actual XML within VB. I think that's called encapsulation, but I may be confused about that too. I could send that message, but it's just basic XML.

The Destination of the Data are various websites who require the data as XML. Either they provide, or I have written, XSDs for the XML data these websites require. VS has a handy tool to create proxy classes (just like with the WSDL) from these XSDs. I can then populate these proxy classes with the data from the Database Objects (which again, is just one record. It's just that I get it as a VB Object), serialize these Objects as XML, and zip them off to these websites.

Right now, I use a fun system of Reflection and CallByName procedures and parsing text files and it was a fun project, but it's crazy and limited, and I know there is a simpler way.

So I wonder, is there a smart way to "hard bind" the Property in one Object to a corresponding Property in a different object. And Interface maybe that helps define this relationship.

Thanks so much for trying to help.
 
Back
Top