better-genshin-impact/BetterGenshinImpact/Markup/ServiceLocatorExtension.cs

21 lines
457 B
C#
Raw Permalink Normal View History

2024-03-10 02:40:40 +08:00
using System;
using System.Windows.Markup;
namespace BetterGenshinImpact.Markup;
[MarkupExtensionReturnType(typeof(object))]
public class ServiceLocatorExtension : MarkupExtension
{
public Type Type { get; set; } = null!;
public ServiceLocatorExtension()
{
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
2024-08-14 18:01:02 +08:00
ArgumentNullException.ThrowIfNull(Type);
2024-03-10 02:40:40 +08:00
return App.GetService(Type)!;
}
}