mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-02 15:50:47 +08:00
refactor(flow) : 重新实现了UIContextOperation的注入逻辑,为后续开发Avalonia版本的编辑器做准备。
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Serein.Library.Utils
|
||||
/// <summary>
|
||||
/// Json门户类,需要你提供实现
|
||||
/// </summary>
|
||||
private static IJsonProvider provider;
|
||||
public static IJsonProvider Provider { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 使用第三方包进行解析
|
||||
@@ -20,7 +20,7 @@ namespace Serein.Library.Utils
|
||||
/// <param name="jsonPortal"></param>
|
||||
public static void UseJsonProvider(IJsonProvider jsonPortal)
|
||||
{
|
||||
JsonHelper.provider = jsonPortal;
|
||||
JsonHelper.Provider = jsonPortal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,7 +32,7 @@ namespace Serein.Library.Utils
|
||||
|
||||
public static T Deserialize<T>(string jsonText)
|
||||
{
|
||||
return provider.Deserialize<T>(jsonText);
|
||||
return Provider.Deserialize<T>(jsonText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,7 +43,7 @@ namespace Serein.Library.Utils
|
||||
/// <returns></returns>
|
||||
public static object Deserialize(string jsonText, Type type)
|
||||
{
|
||||
return provider.Deserialize(jsonText, type);
|
||||
return Provider.Deserialize(jsonText, type);
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Serein.Library.Utils
|
||||
|
||||
public static IJsonToken Parse(string json)
|
||||
{
|
||||
return provider.Parse(json);
|
||||
return Provider.Parse(json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -66,7 +66,7 @@ namespace Serein.Library.Utils
|
||||
/// <returns></returns>
|
||||
public static bool TryParse(string json, out IJsonToken jsonToken)
|
||||
{
|
||||
return provider.TryParse(json, out jsonToken);
|
||||
return Provider.TryParse(json, out jsonToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Serein.Library.Utils
|
||||
/// <returns></returns>
|
||||
public static string Serialize(object obj)
|
||||
{
|
||||
return provider.Serialize(obj);
|
||||
return Provider.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -90,7 +90,7 @@ namespace Serein.Library.Utils
|
||||
{
|
||||
var dict = new Dictionary<string, object>();
|
||||
init(dict);
|
||||
return provider.CreateObject(dict);
|
||||
return Provider.CreateObject(dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,7 +100,7 @@ namespace Serein.Library.Utils
|
||||
/// <returns></returns>
|
||||
public static IJsonToken Array(IEnumerable<object> values)
|
||||
{
|
||||
return provider.CreateArray(values);
|
||||
return Provider.CreateArray(values);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,8 +111,8 @@ namespace Serein.Library.Utils
|
||||
public static IJsonToken FromObject(object obj)
|
||||
{
|
||||
if (obj is System.Collections.IEnumerable && !(obj is string))
|
||||
return provider.CreateObject(obj as IDictionary<string, object>);
|
||||
return provider.CreateArray(obj as IEnumerable<object>);
|
||||
return Provider.CreateObject(obj as IDictionary<string, object>);
|
||||
return Provider.CreateArray(obj as IEnumerable<object>);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -9,7 +10,18 @@ using System.Text;
|
||||
|
||||
namespace Serein.Library.Utils
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 指示IOC扫描构造函数时的行为
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Constructor)]
|
||||
public sealed class SereinIOCCtorAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 忽略该构造函数
|
||||
/// </summary>
|
||||
public bool IsIgnore = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 一个轻量级的单例IOC容器
|
||||
/// </summary>
|
||||
@@ -380,7 +392,19 @@ namespace Serein.Library.Utils
|
||||
/// <returns></returns>
|
||||
private ConstructorInfo[] GetConstructor(Type type)
|
||||
{
|
||||
return type.GetConstructors().OrderByDescending(ctor => ctor.GetParameters().Length).ToArray();
|
||||
return type.GetConstructors().Where(ctor =>
|
||||
{
|
||||
var attribute = ctor.GetCustomAttribute<SereinIOCCtorAttribute>();
|
||||
if (attribute is null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return !attribute.IsIgnore;
|
||||
}
|
||||
})
|
||||
.OrderByDescending(ctor => ctor.GetParameters().Length).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -556,6 +580,11 @@ namespace Serein.Library.Utils
|
||||
if (typeName.Equals("Serein.Library.LightweightFlowEnvironment"))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (_registerCallback.TryGetValue(typeName, out var registerCallback))
|
||||
{
|
||||
|
||||
}
|
||||
if (_dependencies.ContainsKey(typeName))
|
||||
{
|
||||
|
||||
@@ -34,11 +34,15 @@ namespace Serein.Library.Utils
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 传入UI线程上下文
|
||||
/// </summary>
|
||||
/// <param name="synchronizationContext">线程上下文</param>
|
||||
[SereinIOCCtor(IsIgnore = true)]
|
||||
public UIContextOperation(SynchronizationContext synchronizationContext)
|
||||
{
|
||||
this.context = synchronizationContext;
|
||||
@@ -48,6 +52,7 @@ namespace Serein.Library.Utils
|
||||
/// 传入获取UI线程上下文的闭包创建
|
||||
/// </summary>
|
||||
/// <param name="getUiContext">获取线程上下文的闭包函数</param>
|
||||
[SereinIOCCtor(IsIgnore = true)]
|
||||
public UIContextOperation(Func<SynchronizationContext> getUiContext)
|
||||
{
|
||||
this.getUiContext = getUiContext;
|
||||
|
||||
Reference in New Issue
Block a user