Collection Name Generation
Last time we were looking at how to replace the default names used for serializing collections, such as ArrayOfKeyValueOfstringArrayOfstringty7Ep6D1, with more intelligible names. However, where did that funny looking name come from in the first place?
The generation of default names is based on straightforward substitution and appending of data contract names.
The default name of a list is ArrayOf followed by the name of the data contract that describes the list’s contents.
Similarly, the default name of a dictionary is ArrayOfKeyValue followed by the names of the data contracts that describes the dictionary’s keys and the dictionary’s values. Thus, you can think of a dictionary as being modeled as an array of entries, each entry a data contract named KeyValue followed by the names of the data contracts that describes the dictionary’s keys and the dictionary’s values. In fact, that’s exactly the name of the data contract that describes the entry.
The usual subtleties of data contract naming apply for collection names. For example, when generic parameters are used, the name is further appended with a hash based on the data contract namespace if the types involved are not primitive types. That’s where the ty7Ep6D1 comes from in this case. As another example, you have to be careful to distinguish the data contract names being used here from type names. In some cases, the data contract name and type name look the same, such as string being named string. In other cases, the data contract name and type name look quite different, such as object being named anyType.