1

I am building web service in C# for a particular application, I have a XML definition of module. I have created a class called Field that holds the properties of all fields on a module. What I would like to do is create the field objects but name them dynamically then add them to a list of some sort. So when I reference them from the client it would be like this:

Module.Fields.MyDynamicName.FieldProperty

Is this possible to do? and could anyone point me in the right direction on how to do this.

Hope my question makes sense.

est005
  • 138
  • 2
  • 8
  • 1
    I dont think that is possible . But you can do a dictionary property and add the item as propertyname and value, then access it by propertyName – Dan Hunex Mar 21 '14 at 18:37
  • I have tried a Dictionary but it need to be serialized because I am using it in a web service. I have seen something like this done in other web services – est005 Mar 21 '14 at 18:39
  • 1
    Look at this as to how you can serialize a dictionary http://stackoverflow.com/questions/12554186/how-to-serialize-deserialize-to-dictionaryint-string-from-custom-xml-not-us – Dan Hunex Mar 21 '14 at 18:47

1 Answers1

1

Basically you need to design for "deferred design", which means you do not know at compile time what the design is, but you still need to accommodate it.

There are probably a few ways but what I have done in the past is use a dictionary list of Key/Value pairs to store fields. Using serialization (I prefer Json) you can shove just about anything into a string and store it as the Value, then deserialize it when you need it.

Eric Scherrer
  • 3,328
  • 1
  • 19
  • 34
  • None that I know of for the application layer, but you can look into the EAV (Entity attribute Value) database structure for ideas on how to persist and retrieve KVP's. – Eric Scherrer Mar 21 '14 at 19:04