protected Dictionary <TKey, TElement> DictionaryReader(string text) { var elements = new Dictionary <TKey, TElement>(); if (string.IsNullOrEmpty(text)) { return(elements); } try { ReadMap(text, (keyText, valueText) => { TKey key = KeyReader(keyText); TElement value = ElementReader(valueText); elements[key] = value; }); } catch (Exception ex) { throw TypeSerializerException.New <IDictionary <TKey, TElement> >(text, ex); } return(elements); }
private T StringToInstance(string text) { if (text[0] != MapStart) { string message = string.Format("Types should start with a '{0}', expecting serialized type '{1}', got string starting with: {2}", MapStart, typeof(T).Name, text.Substring(0, text.Length < 50 ? text.Length : 50)); throw new SerializationException(message); } T instance = FastActivator <T> .Create(); try { ReadMap(text, (key, value) => _properties.WithValue(key, serializer => serializer.Read(instance, value))); } catch (Exception ex) { throw TypeSerializerException.New(this, text, ex); } return(instance); }