Receiving multiple data structures and mapping them to one object

So I need a bit of help, completely lost. I've seen several different ways I think I can do this, but either I suck completely or they're just poor ways to accomplish this task.

There are several different types of providers we use to send us data. All of them just submit their data through query strings to our web page, which we then grab and do whatever we want with.

The time has come that we need to make the software flexible for each individual type (and allow them to specify the type they are using, instead of hard-coding it). I could just simply create a method, figure out which type I'm listening for, and parse it for each type within that method. However, I want to get to the point where we can add new types by simply modifying an external library or a row in a database even so updates become very simple, or we can create our own types on the fly.

What I'm having trouble with is mapping the different strings into a singular object. So, let's say I have "OneType" and "TwoType", each carry the same information I want, but have different field names and as such must be parsed differently (also no guarantee on order). I don't want to create a method for each possible parse, I want to say "Hey, you know this is type 2, here's how we map it to my 'Message' object". But wait, here comes type 1 message, I still know how to map to 'Message'.

I apologize for the ramble, I don't even know if I am asking properly but I know I'm right on the edge of figuring it out. Just need a nudge.

Feel free to also call me a retard because I feel like I'm overthinking the hell out of this.

Example string 1: ?id=6&name=blah&message=Hi+Dude Example string 2: ?myName=blah&myId=6&yourMessage=Hi+Dude Object: public sealed class IncomingMessage { public int Id { get; set; } public string Message { get; set; } public string Name { get; set; } } 

by ihatesignupscreens via /r/csharp

Leave a Reply