private static IStringProperty SettingToProperty(SettingElement setting) { if (setting == null) { return(null); } return(new StringProperty(setting.Name, XmlEscaper.Unescape(setting.Value.ValueXml.InnerXml))); }
protected static KeyValuePair <string, string> ParseParameter(string content, ref int currentIndex) { var endIndex = content.IndexOf('=', currentIndex); if (endIndex < 0) { throw new InvalidOperationException("Unrecognized format of TCP message content (badly formatted parameter for item): " + content); } var key = content.Substring(currentIndex, endIndex - currentIndex); currentIndex = endIndex + 1; var quoted = false; if (content[currentIndex] == StringQuoter) { endIndex = content.IndexOf(StringQuoter, ++currentIndex); quoted = true; } else { var andIndex = content.IndexOf(Seperator, currentIndex); var objectEndIndex = content.IndexOf('>', currentIndex) - 1; // Take the nearest match endIndex = Math.Min(andIndex, objectEndIndex); if (endIndex < 0) { endIndex = Math.Max(andIndex, objectEndIndex); } } if (endIndex < 0) { throw new InvalidOperationException("Unrecognized format of TCP message content (bad quotation of item parameter value): " + content); } string value; if (endIndex > currentIndex) { value = XmlEscaper.Unescape(content.Substring(currentIndex, endIndex - currentIndex)); } else if (quoted) { value = string.Empty; } else { value = null; } currentIndex = endIndex; if (quoted || value == null) { currentIndex++; } return(new KeyValuePair <string, string>(key, value)); }