using System; using System.Collections.Generic; using System.Xml.Serialization; namespace Wayne.ForecourtControl.Fusion { public static class CachingXmlSerializer { private static readonly Dictionary Cache = new Dictionary(); private static readonly object SyncRoot = new object(); public static XmlSerializer Create() { var type = typeof (T); if (type == null) throw new ArgumentNullException("type"); lock (SyncRoot) { if (!Cache.ContainsKey(type)) { Cache.Add(type, new XmlSerializer(type)); } } return Cache[type]; } } }