using System; using System.Collections.Generic; using System.Linq; using System.Threading; using Umbraco.Core.ObjectResolution; namespace Umbraco.Core.PropertyEditors { /// /// Resolves the IPropertyValueConverter objects. /// public sealed class PropertyValueConvertersResolver : ManyObjectsResolverBase { /// /// Initializes a new instance of the class with /// an initial list of converter types. /// /// The list of converter types /// The resolver is created by the WebBootManager and thus the constructor remains internal. internal PropertyValueConvertersResolver(IEnumerable converters) : base(converters) { } /// /// Initializes a new instance of the class with /// an initial list of converter types. /// /// The list of converter types /// The resolver is created by the WebBootManager and thus the constructor remains internal. internal PropertyValueConvertersResolver(params Type[] converters) : base(converters) { } /// /// Gets the converters. /// public IEnumerable Converters { get { return Values; } } private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(); private Tuple[] _defaults = null; /// /// Caches and gets the default converters with their metadata /// internal Tuple[] DefaultConverters { get { using (var locker = new UpgradeableReadLock(_lock)) { if (_defaults == null) { locker.UpgradeToWriteLock(); var defaultConvertersWithAttributes = Converters .Select(x => new { attribute = x.GetType().GetCustomAttribute(false), converter = x }) .Where(x => x.attribute != null) .ToArray(); _defaults = defaultConvertersWithAttributes .Select( x => new Tuple(x.converter, x.attribute)) .ToArray(); } return _defaults; } } } } }