When POSTing data to a third-party payment provider, I usually serialize an MVC model which represents the fields. I have used this technique many times and has worked perfectly.
However now I am faced with this specification:

Note that the field names contain square brackets. I can’t work out how to include the full field name in my model properties, currently the model looks like this:
public string action { get; set; }
public string api_key { get; set; }
public string RetailerUniqueRef { get; set; }
public string InstallationID { get; set; }
public float Price { get; set; }
public string Description { get; set; }
public string Code { get; set; }
public float Deposit { get; set; }
public string SchemeCode { get; set; }
As you can see, the property names are only part of the field names. If I add the square brackets like so:
public string identification[api_key] { get; set; }
This fails as the compiler quite rightly thinks it’s an array.
How can I include the square brackets in the property names, or is there another way round this?
Perhaps you could use some form of attribute to mark up your property then use reflection to get the name. However in the example you have provided the
dataobject is aNameValueCollectionwith the key being a string, meaning there is no need to do so or even use the property name.I suspect that you will need to do something like this:-