Map Literals to Object Properties/Values
Posted
by vijay
on Stack Overflow
See other posts from Stack Overflow
or by vijay
Published on 2010-05-20T10:09:33Z
Indexed on
2010/05/20
10:10 UTC
Read the original article
Hit count: 216
c#
For eg, my input XML is look like this.
<root>
<myelemt>
<input type="variable">
<variable>STARTDATE</variable>
<variable>CUSTOMERNAME</variable>
</input>
</myelemt>
</root>
it is deserialized and loaded into the object MyXmlElemtObj
in my code i have written like this,
if(MyXmlElemtObj.input.variable.ToUpper() == "STARTDATE")
ProcessObjectB(ObjectA.OrderDate);
if(MyXmlElemtObj.input.variable.ToUpper() == "CUSTOMERNAME")
ProcessObjectB(ObjectC.UserName);
Here I am mapping those input literals to some objects value.
The one thing that scares me is seeing some ** hard-coded literals** all over my code.
Instead i would like to write something like ProcessObjectB(Common.GetMappedvalue(MyXmlElemtObj.input.variable));
Is there a way to isolate this mapping thing to common class, where i will predefine which literal is mapped to which values. The problem is the values are of objects created at the run time.
If my question is making sense then So how do i achieve this?
I think i have given all the necessary details. if anything is missing please metnion. Thx Much.
© Stack Overflow or respective owner