123456789101112131415161718192021222324252627282930 |
- using System;
- using System.Collections.Generic;
- using System.Xml.Serialization;
- namespace Wayne.ForecourtControl.Fusion
- {
- public static class CachingXmlSerializer
- {
- private static readonly Dictionary<Type, XmlSerializer> Cache = new Dictionary<Type, XmlSerializer>();
- private static readonly object SyncRoot = new object();
- public static XmlSerializer Create<T>()
- {
- 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];
- }
- }
- }
|