Add project files.

This commit is contained in:
Daniel Clark
2022-11-01 15:26:08 +00:00
parent daa7b59f22
commit 7e4f880821
408 changed files with 16863 additions and 0 deletions
@@ -0,0 +1,36 @@
namespace TheXamlGuy.Framework.Core
{
public class NamedDataTemplateFactory : INamedDataTemplateFactory
{
private readonly Dictionary<string, object> dataTracking = new();
private readonly IReadOnlyCollection<ITemplateDescriptor> descriptors;
private readonly IServiceFactory serviceFactory;
public NamedDataTemplateFactory(IReadOnlyCollection<ITemplateDescriptor> descriptors,
IServiceFactory serviceFactory)
{
this.descriptors = descriptors;
this.serviceFactory = serviceFactory;
}
public virtual object? Create(string name, params object[] parameters)
{
if (dataTracking.TryGetValue(name, out object? data))
{
return data;
}
if (descriptors.FirstOrDefault(x => x.Name == name) is ITemplateDescriptor descriptor)
{
data = parameters is { Length: > 0 } ? serviceFactory.Create<object>(descriptor.DataType, parameters) : serviceFactory.Get<object>(descriptor.DataType);
if (data is ICachable cachable)
{
dataTracking[name] = cachable;
}
}
return data;
}
}
}