Wrap FluentAvalonia controls within same named classes allowing us to declare the xmlns namespace in our assembly

This commit is contained in:
Daniel Clark
2022-12-10 15:52:58 +00:00
parent 3d9a7e4438
commit 4f243eba2e
94 changed files with 121 additions and 85 deletions
@@ -0,0 +1,26 @@
namespace Toolkit.Foundation
{
public class ServiceFactory : IServiceFactory
{
private readonly Func<Type, object?> factory;
private readonly Func<Type, object?[], object> creator;
public ServiceFactory(Func<Type, object?> factory, Func<Type, object?[], object> creator)
{
this.factory = factory;
this.creator = creator;
}
public object? Create(Type type, params object?[] parameters)
{
dynamic? lookup = factory(typeof(IServiceCreator<>).MakeGenericType(type));
return lookup is not null ? lookup.Create(creator, parameters) : creator(type, parameters);
}
public T? Create<T>(Type type, params object?[] parameters)
{
dynamic? lookup = factory(typeof(IServiceCreator<>).MakeGenericType(type));
return lookup is not null ? (T)lookup.Create(creator, parameters) : (T)creator(type, parameters);
}
}
}