internal static TileData FromXmlReader(XmlReader reader) { reader.ValidateNodeType(XmlNodeType.Element); var type = TileTypeHelper.FromElementName(reader.Name); Dictionary <string, string> attributes; if (reader.MoveToFirstAttribute()) { attributes = new Dictionary <string, string>(); do { attributes.Add(reader.Name, reader.Value); }while (reader.MoveToNextAttribute()); } else { attributes = null; } reader.ValidatedRead(); reader.ValidateNodeType(XmlNodeType.Text); var content = reader.Value; var tile = TileData.Create(type: type, content: content, attributes: attributes); reader.ValidatedRead(); reader.ReadNodeType(XmlNodeType.EndElement); return(tile); }
public static TileData Create(string content, bool isPrefix = false, bool isSuffix = false, IReadOnlyDictionary <string, string> attributes = null) { var type = TileTypeHelper.FromFixes(isPrefix: isPrefix, isSuffix: isSuffix); var value = new TileData(type: type, content: content, attributes: attributes); return(value); }
public static TileData FromTokenString(string token) { TileData value; var splits = token.Split('\0'); if (splits.Length == 1) { value = TileData.Create(token); } else { var content = splits[0]; var type = TileType.Normal; Dictionary <string, string> attributes = null; for (var i = 1; i < splits.Length; i++) { var attributeKeyValue = splits[i]; if (attributeKeyValue.Length == 1) { type = TileTypeHelper.FromElementName(attributeKeyValue); } else { if (attributes == null) { attributes = new Dictionary <string, string>(); } var keyValue = attributeKeyValue.Split(new[] { '=' }, 2); attributes.Add(keyValue[0], keyValue[1]); } } value = TileData.Create(content: content, type: type, attributes: attributes); } return(value); }