修复了已知的bug

This commit is contained in:
fengjiayi
2025-09-04 10:39:57 +08:00
parent f9ab920939
commit 51c268baad
28 changed files with 1099 additions and 108 deletions

View File

@@ -257,7 +257,16 @@ namespace Serein.Library.Utils
object result;
if (type.IsEnum)
{
result = Enum.Parse(type, valueStr);
if (int.TryParse(valueStr, out int numericValue))
{
// 输入是数字,直接转换
result = Enum.ToObject(type, numericValue);
}
else
{
// 输入是枚举名称
result = Enum.Parse(type, valueStr, ignoreCase: true);
}
}
else if (type == typeof(bool))
{

View File

@@ -125,6 +125,7 @@ namespace Serein.Library
public static void WriteLine(InfoType type, string message, InfoClass @class = InfoClass.General)
{
Debug.WriteLine($"{type} : {message}");
Console.WriteLine($"{type} : {message}");
SereinEnv.environment?.WriteLine(type,message,@class);
}

View File

@@ -194,16 +194,15 @@ namespace Serein.Library.Utils
/// <param name="instance"></param>
/// <returns></returns>
public T InjectDependenciesProperty<T>(T instance)
{
{
var type = instance.GetType();
var properties = type.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).ToArray()
.Where(p => p.CanWrite // 可写属性
&& p.GetCustomAttribute<AutoInjectionAttribute>() != null // 有特性标注需要注入
&& p.GetValue(instance) == null); // 属性为空
var propertys = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
.Where(p => p.CanWrite // 可写属性
&& p.GetCustomAttribute<AutoInjectionAttribute>() is not null // 有特性标注需要注入
&& p.GetValue(instance) is null); // 属性为空
// 属性注入
foreach (var property in properties)
foreach (var property in propertys)
{
var propertyType = property.PropertyType;
if (_dependencies.TryGetValue(propertyType.FullName, out var dependencyInstance))
@@ -215,7 +214,7 @@ namespace Serein.Library.Utils
// 字段注入
var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic )
.Where(f => f.GetCustomAttribute<AutoInjectionAttribute>() != null
.Where(f => f.GetCustomAttribute<AutoInjectionAttribute>() != null
&& f.GetValue(instance) == null);
foreach (var field in fields)