1
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user