File: PlatformConfigurationRegistry.cs
Web Access
Project: src\src\Controls\src\Core\Controls.Core.csproj (Microsoft.Maui.Controls)
#nullable disable
using System;
using System.Collections.Generic;
 
namespace Microsoft.Maui.Controls
{
	/// <inheritdoc/>
	public class PlatformConfigurationRegistry<TElement> : IElementConfiguration<TElement>
		where TElement : Element
	{
		readonly TElement _element;
		readonly Dictionary<Type, object> _platformSpecifics = new Dictionary<Type, object>();
 
		public PlatformConfigurationRegistry(TElement element)
		{
			_element = element;
		}
 
		/// <inheritdoc/>
		public IPlatformElementConfiguration<T, TElement> On<T>() where T : IConfigPlatform
		{
			if (_platformSpecifics.ContainsKey(typeof(T)))
			{
				return (IPlatformElementConfiguration<T, TElement>)_platformSpecifics[typeof(T)];
			}
 
			var emptyConfig = Configuration<T, TElement>.Create(_element);
 
			_platformSpecifics.Add(typeof(T), emptyConfig);
 
			return emptyConfig;
		}
	}
}