mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-07 08:26:34 +08:00
修复了已知的bug
This commit is contained in:
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user