简体   繁体   中英

Configurable code logic in C#

I have a xml data where nodes are present like this

<segment>
<country>US</country>
<prop>Supplier</prop>       
</segment>

The scenario is my business entity is strongly bound with this XML. Now we have to rearchitect the system to make it more scalable. The node names in the xml may change in the future.

<prop>Supplier</prop>

may change to

<name>Supplier</name>

So how to write a dynamic C# code to support this feature ?

You can add version or parsing engine to your xml, so it can look something like that:

<root>
  <parseEngine type="version2" />
  <!-- Rest of xml -->
</root>

And in C# you you first read this node and then select parsing method.

I have finally written code to fetch the data using XML configuration.

<Properties>
<NodeName>prop<NodeName>
</Properties>

So now I will read this configuration and fetch the data from XML using the node name from Configuration.By This way I can dynamically process my data.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM