Exemplo n.º 1
0
		IReadOnlyList<XElement> SaveContents()
		{
			List<XElement> result = new List<XElement>();
			foreach (var pair in dict) {
				XAttribute key = new XAttribute("key", pair.Key);
				Properties child = pair.Value as Properties;
				if (child != null) {
					var contents = child.SaveContents();
					if (contents.Count > 0)
						result.Add(new XElement("Properties", key, contents));
				} else if (pair.Value is object[]) {
					object[] array = (object[])pair.Value;
					XElement[] elements = new XElement[array.Length];
					for (int i = 0; i < array.Length; i++) {
						XElement obj = array[i] as XElement;
						if (obj != null) {
							elements[i] = new XElement(obj);
						} else if (array[i] == null) {
							elements[i] = new XElement("Null");
						} else {
							elements[i] = new XElement("Element", (string)array[i]);
						}
					}
					result.Add(new XElement("Array", key, elements));
				} else if (pair.Value is XElement) {
					result.Add(new XElement((XElement)pair.Value));
				} else {
					result.Add(new XElement("Property", key, (string)pair.Value));
				}
			}
			return result;
		}