private void RecursiveSerializeGroup(IConfigurationGroup rootGroup, XmlWriter xw) { xw.WriteStartElement(_XmlElementGroupName_); xw.WriteAttributeString(_XmlElementGroupKeyName_, rootGroup.Key); if (rootGroup.Items.Count > 0) { xw.WriteStartElement(_XmlElementGroupItemsName_); foreach (var item in rootGroup.Items) { xw.WriteStartElement(_XmlElementItemName_); xw.WriteAttributeString(_XmlElementItemKeyName_, item.Key); xw.WriteAttributeString(_XmlElementItemTypeName_, ConfigurationShared.ConvertItemTypeToString(item)); xw.WriteString(ConfigurationShared.ConvertItemObjectToString(item, _Compressor)); xw.WriteEndElement(); } xw.WriteEndElement(); } if (rootGroup.Count > 0) { xw.WriteStartElement(_XmlElementGroupsName_); foreach (var subGroup in rootGroup) { RecursiveSerializeGroup(subGroup, xw); } xw.WriteEndElement(); } xw.WriteEndElement(); }
private StringBuilder InternalSerializeItem(IConfigurationItem item, bool includeTypeInformation) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (includeTypeInformation) { // full format var typeStr = ConfigurationShared.ConvertItemTypeToString(item); if (typeStr.Contains(_IniElementSeparator_)) { typeStr = "\"" + typeStr + "\""; } return(new StringBuilder($"{item.Key}{_IniElementSeparator_}{typeStr}{_IniElementSeparator_}{ConfigurationShared.ConvertItemObjectToString(item, _Compressor)}")); } else { // classic style return(new StringBuilder($"{item.Key}{_IniElementSeparator_}{ConfigurationShared.ConvertItemObjectToString(item, _Compressor)}")); } }
private void InternalSerializeGroup(string parentGroupAddress, IConfigurationGroup group, DelimiterSeparatedValues.DsvTable table) { // get local Group Address var groupAddress = group.Key; if (!string.IsNullOrWhiteSpace(parentGroupAddress)) { groupAddress = parentGroupAddress + _CsvGroupNameSeparator_ + group.Key; } // process items if (group.Items.Count > 0) { // serialize items foreach (var item in group.Items) { var row = table.NewRow(groupAddress, item.Key, ConfigurationShared.ConvertItemTypeToString(item), ConfigurationShared.ConvertItemObjectToString(item, _Compressor)); table.Rows.Add(row); } } else { var row = table.NewRow(groupAddress); if (row != null) { if (!string.IsNullOrWhiteSpace((string)row[0])) { table.Rows.Add(row); } else if ((!string.IsNullOrWhiteSpace((string)row[1])) && (!string.IsNullOrWhiteSpace((string)row[2])) && (!string.IsNullOrWhiteSpace((string)row[3]))) { table.Rows.Add(row); } } } // process groups if (group.Count > 0) { foreach (var subGroup in group) { InternalSerializeGroup(groupAddress, subGroup, table); } } }