private Func <XmlGridRowReader, object> GetDeserializer( XmlGridRowReader reader) { reader.ReadRow(); if (!reader.Columns.Any()) { throw new InvalidOperationException("No columns"); } var key = new DeserializerKey(reader.Columns); if (!deserializers.TryGetValue(key, out var deserializer)) { lock (deserializers) { if (!deserializers.TryGetValue(key, out deserializer)) { deserializer = CreateDeserializer(type, reader.Columns); deserializers.Add(key, deserializer); } } } return(deserializer); }
public static IEnumerable <T> Read <T>(string xml) { if (xml is null) { throw new ArgumentNullException(nameof(xml)); } using (var reader = new XmlGridRowReader(xml)) { var result = new List <T>(); if (!reader.MoveToGrid()) { return(result); } var deserializer = GetDeserializer(typeof(T), reader); // Assumes XML is well formed // Reader will already be positioned on a row, so excute // a deserialize at least once do { var obj = deserializer(reader); result.Add((T)obj); } while (reader.ReadRow()); return(result); } }
public static Func <XmlGridRowReader, object> GetDeserializer( Type type, XmlGridRowReader reader) { if (!byType.TryGetValue(type, out var deserializers)) { lock (byType) { if (!byType.TryGetValue(type, out deserializers)) { deserializers = new TypeDeserializerCache(type); } byType.Add(type, deserializers); } } return(deserializers.GetDeserializer(reader)); }
private static Func <XmlGridRowReader, object> GetDeserializer( Type type, XmlGridRowReader reader) { return(TypeDeserializerCache.GetDeserializer(type, reader)); }