This commit is contained in:
CortexCore
2024-05-31 01:23:15 +08:00
parent c798b224be
commit 299082fe27
164 changed files with 3604 additions and 2018 deletions

View File

@@ -125,6 +125,29 @@ namespace BITKit
/// <param name="obj"></param>
public static void Inject(object obj)
{
foreach (var propertyInfo in obj.GetType().GetProperties(ReflectionHelper.Flags))
{
try
{
if (propertyInfo.GetCustomAttribute<ObsoleteAttribute>() is null &&
propertyInfo.GetCustomAttribute<InjectAttribute>() is not null)
{
lock (dictionary)
{
if(dictionary!.TryGetValue(propertyInfo.PropertyType,out var value))
{
BIT4Log.Log<DI>($"已为{obj.GetType().Name}.{propertyInfo.Name}注入{value.GetType().Name}");
propertyInfo.SetValue(obj,value);
}
}
}
}
catch (Exception e)
{
BIT4Log.LogException(e);
}
}
foreach (var field in obj.GetType().GetFields(ReflectionHelper.Flags))
{
try