diff --git a/Library/FlowNode/MethodDetails.cs b/Library/FlowNode/MethodDetails.cs index ad3021c..0a22fa7 100644 --- a/Library/FlowNode/MethodDetails.cs +++ b/Library/FlowNode/MethodDetails.cs @@ -342,7 +342,7 @@ namespace Serein.Library } sb.AppendLine(); sb.AppendLine($"返回值信息:"); - sb.AppendLine($"\t{this.ReturnType?.FullName}"); + sb.AppendLine($"\t{this.ReturnType?.GetFriendlyName()}"); return sb.ToString(); } diff --git a/Library/FlowNode/ParameterDetails.cs b/Library/FlowNode/ParameterDetails.cs index b8c637b..80f0b2e 100644 --- a/Library/FlowNode/ParameterDetails.cs +++ b/Library/FlowNode/ParameterDetails.cs @@ -499,7 +499,7 @@ namespace Serein.Library /// public override string ToString() { - return $"[{this.Index}] {(string.IsNullOrWhiteSpace(this.Description) ? string.Empty : $"({this.Description})")}{this.Name} : {this.DataType?.FullName}"; + return $"[{this.Index}] {(string.IsNullOrWhiteSpace(this.Description) ? string.Empty : $"({this.Description})")}{this.Name} : {this.DataType?.GetFriendlyName()}"; } } diff --git a/Library/ScriptBaseFunc.cs b/Library/ScriptBaseFunc.cs index 5e83303..0e01eae 100644 --- a/Library/ScriptBaseFunc.cs +++ b/Library/ScriptBaseFunc.cs @@ -27,7 +27,7 @@ namespace Serein.Library /// public static bool @bool(object value) { - return ConvertHelper.ValueParse(value); + return ObjectConvertHelper.ValueParse(value); } /// @@ -37,7 +37,7 @@ namespace Serein.Library /// public static byte @byte(object value) { - return ConvertHelper.ValueParse(value); + return ObjectConvertHelper.ValueParse(value); } /// @@ -47,7 +47,7 @@ namespace Serein.Library /// public static decimal @decimal(object value) { - return ConvertHelper.ValueParse(value); + return ObjectConvertHelper.ValueParse(value); } /// @@ -57,7 +57,7 @@ namespace Serein.Library /// public static float @float(object value) { - return ConvertHelper.ValueParse(value); + return ObjectConvertHelper.ValueParse(value); } /// @@ -67,7 +67,7 @@ namespace Serein.Library /// public static double @double(object value) { - return ConvertHelper.ValueParse(value); + return ObjectConvertHelper.ValueParse(value); } /// @@ -77,7 +77,7 @@ namespace Serein.Library /// public static int @int(object value) { - return ConvertHelper.ValueParse(value); + return ObjectConvertHelper.ValueParse(value); } /// @@ -87,7 +87,7 @@ namespace Serein.Library /// public static int @long(object value) { - return ConvertHelper.ValueParse(value); + return ObjectConvertHelper.ValueParse(value); } #endregion diff --git a/Library/Utils/ConvertHelper.cs b/Library/Utils/ConvertHelper.cs deleted file mode 100644 index 4e4a13b..0000000 --- a/Library/Utils/ConvertHelper.cs +++ /dev/null @@ -1,370 +0,0 @@ -using System; -using System.Globalization; - -namespace Serein.Library.Utils -{ - /// - /// 类型转换工具类 - /// - public static class ConvertHelper - { - /// - /// 字面量转为对应类型 - /// - /// - /// - public static Type ToTypeOfString(this string valueStr) - { - if (valueStr.IndexOf('.') != -1) - { - // 通过指定的类型名称获取类型 - return Type.GetType(valueStr); - } - - - if (valueStr.Equals("bool", StringComparison.OrdinalIgnoreCase)) - { - return typeof(bool); - } - #region 整数型 - else if (valueStr.Equals("sbyte", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(SByte), StringComparison.OrdinalIgnoreCase)) - { - return typeof(SByte); - } - else if (valueStr.Equals("short", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(Int16), StringComparison.OrdinalIgnoreCase)) - { - return typeof(Int16); - } - else if (valueStr.Equals("int", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(Int32), StringComparison.OrdinalIgnoreCase)) - { - return typeof(Int32); - } - else if (valueStr.Equals("long", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(Int64), StringComparison.OrdinalIgnoreCase)) - { - return typeof(Int64); - } - - else if (valueStr.Equals("byte", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(Byte), StringComparison.OrdinalIgnoreCase)) - { - return typeof(Byte); - } - else if (valueStr.Equals("ushort", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(UInt16), StringComparison.OrdinalIgnoreCase)) - { - return typeof(UInt16); - } - else if (valueStr.Equals("uint", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(UInt32), StringComparison.OrdinalIgnoreCase)) - { - return typeof(UInt32); - } - else if (valueStr.Equals("ulong", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(UInt64), StringComparison.OrdinalIgnoreCase)) - { - return typeof(UInt64); - } - #endregion - - #region 浮点型 - else if (valueStr.Equals("float", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(Single), StringComparison.OrdinalIgnoreCase)) - { - return typeof(Single); - } - else if (valueStr.Equals("double", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(Double), StringComparison.OrdinalIgnoreCase)) - { - return typeof(Double); - } - #endregion - - #region 小数型 - - else if (valueStr.Equals("decimal", StringComparison.OrdinalIgnoreCase) - || valueStr.Equals(nameof(Decimal), StringComparison.OrdinalIgnoreCase)) - { - return typeof(Decimal); - } - #endregion - - #region 其他常见的类型 - else if (valueStr.Equals(nameof(DateTime), StringComparison.OrdinalIgnoreCase)) - { - return typeof(DateTime); - } - - else if (valueStr.Equals(nameof(String), StringComparison.OrdinalIgnoreCase)) - { - return typeof(String); - } - #endregion - - else - { - throw new ArgumentException($"无法解析的字面量类型[{valueStr}]"); - } - } - - - - - /// - /// 对象转换为对应类型 - /// - /// - /// - /// - public static TResult ToConvert(this object data) - { - var type = typeof(TResult); - if (data is null && type.IsValueType) - { - return default; - } - return (TResult)data.ToConvertValueType(type); - - } - - - /// - /// 对象转换 - /// - /// - /// - /// - public static object ToConvertValueType(this object data, Type type) - { - if (type.IsValueType) - { - if (data == null) - { - return null; - } - else - { - return ConvertHelper.ValueParse(type, data); - } - } - return data; - - } - - - - /// - /// 文本 - /// - /// - /// - /// - public static T ValueParse(object value) where T : struct, IComparable - { - if (value is T data) - { - return data; - } - string valueStr = value.ToString(); - return valueStr.ToValueData() ; - } - - /// - /// 文本转换数值 - /// - /// - /// - /// - public static object ValueParse(Type type, object value) - { - string valueStr = value.ToString(); - return valueStr.ToValueData(type); - - } - - /// - /// 文本转换值对象 - /// - /// - /// - /// - /// - public static T ToValueData(this string valueStr) where T : struct, IComparable - { - if (string.IsNullOrEmpty(valueStr)) - { - throw new NullReferenceException(); - //return default(T); - } - var type = typeof(T); - object result; - if (type.IsEnum) - { - result = Enum.Parse(type, valueStr); - } - else if (type == typeof(bool)) - { - result = bool.Parse(valueStr); - } - else if (type == typeof(float)) - { - result = float.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(decimal)) - { - result = decimal.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(double)) - { - result = double.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(sbyte)) - { - result = sbyte.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(byte)) - { - result = byte.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(short)) - { - result = short.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(ushort)) - { - result = ushort.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(int)) - { - result = int.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(uint)) - { - result = uint.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(long)) - { - result = long.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(ulong)) - { - result = ulong.Parse(valueStr, CultureInfo.InvariantCulture); - } -#if NET6_0 || NET7_0 || NET8_0 - else if (type == typeof(nint)) - { - result = nint.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(nuint)) - { - result = nuint.Parse(valueStr, CultureInfo.InvariantCulture); - } -#endif - else - { - throw new ArgumentException("非预期值类型"); - } - - return (T)result; - } - - /// - /// 将字符串转换为指定类型的值对象。 - /// - /// - /// - /// - /// - public static object ToValueData(this string valueStr, Type type) - { - if (string.IsNullOrWhiteSpace(valueStr)) - { - return Activator.CreateInstance(type); - } - object result; - if (type.IsEnum) - { - result = Enum.Parse(type, valueStr); - } - else if (type == typeof(bool)) - { - result = bool.Parse(valueStr); - } - else if (type == typeof(float)) - { - result = float.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(decimal)) - { - result = decimal.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(double)) - { - result = double.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(sbyte)) - { - result = sbyte.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(byte)) - { - result = byte.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(short)) - { - result = short.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(ushort)) - { - result = ushort.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(int)) - { - result = int.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(uint)) - { - result = uint.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(long)) - { - result = long.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(ulong)) - { - result = ulong.Parse(valueStr, CultureInfo.InvariantCulture); - } -#if NET6_0 || NET7_0 || NET8_0 - else if (type == typeof(nint)) - { - result = nint.Parse(valueStr, CultureInfo.InvariantCulture); - } - else if (type == typeof(nuint)) - { - result = nuint.Parse(valueStr, CultureInfo.InvariantCulture); - } -#endif - else if(type == typeof(DateTime)) - { - if (valueStr.Equals("now")) - { - return DateTime.Now; - } - else if (valueStr.Equals("utcnow")) - { - return DateTime.UtcNow; - } - return DateTime.Parse(valueStr); - } - else - { - throw new ArgumentException("非预期值类型"); - } - - return result; - } - } -} diff --git a/Library/Utils/ObjectConvertHelper.cs b/Library/Utils/ObjectConvertHelper.cs index 06d0a62..f7e0643 100644 --- a/Library/Utils/ObjectConvertHelper.cs +++ b/Library/Utils/ObjectConvertHelper.cs @@ -1,7 +1,9 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Globalization; using System.Linq; +using System.Runtime.CompilerServices; namespace Serein.Library.Utils { @@ -80,5 +82,259 @@ namespace Serein.Library.Utils } + + /// + /// 对象转换为对应类型 + /// + /// + /// + /// + public static TResult ToConvert(this object data) + { + var type = typeof(TResult); + if (data is null && type.IsValueType) + { + return default; + } + return (TResult)data.ToConvertValueType(type); + + } + + + /// + /// 对象转换 + /// + /// + /// + /// + public static object ToConvertValueType(this object data, Type type) + { + if (type.IsValueType) + { + if (data == null) + { + return null; + } + else + { + return ObjectConvertHelper.ValueParse(type, data); + } + } + return data; + + } + + + + /// + /// 文本 + /// + /// + /// + /// + public static T ValueParse(object value) where T : struct, IComparable + { + if (value is T data) + { + return data; + } + string valueStr = value.ToString(); + return valueStr.ToValueData(); + } + + /// + /// 文本转换数值 + /// + /// + /// + /// + public static object ValueParse(Type type, object value) + { + string valueStr = value.ToString(); + return valueStr.ToValueData(type); + + } + + /// + /// 文本转换值对象 + /// + /// + /// + /// + /// + public static T ToValueData(this string valueStr) where T : struct, IComparable + { + if (string.IsNullOrEmpty(valueStr)) + { + throw new NullReferenceException(); + //return default(T); + } + var type = typeof(T); + object result; + if (type.IsEnum) + { + result = Enum.Parse(type, valueStr); + } + else if (type == typeof(bool)) + { + result = bool.Parse(valueStr); + } + else if (type == typeof(float)) + { + result = float.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(decimal)) + { + result = decimal.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(double)) + { + result = double.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(sbyte)) + { + result = sbyte.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(byte)) + { + result = byte.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(short)) + { + result = short.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(ushort)) + { + result = ushort.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(int)) + { + result = int.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(uint)) + { + result = uint.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(long)) + { + result = long.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(ulong)) + { + result = ulong.Parse(valueStr, CultureInfo.InvariantCulture); + } +#if NET6_0 || NET7_0 || NET8_0 + else if (type == typeof(nint)) + { + result = nint.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(nuint)) + { + result = nuint.Parse(valueStr, CultureInfo.InvariantCulture); + } +#endif + else + { + throw new ArgumentException("非预期值类型"); + } + + return (T)result; + } + + /// + /// 将字符串转换为指定类型的值对象。 + /// + /// + /// + /// + /// + public static object ToValueData(this string valueStr, Type type) + { + if (string.IsNullOrWhiteSpace(valueStr)) + { + return Activator.CreateInstance(type); + } + object result; + if (type.IsEnum) + { + result = Enum.Parse(type, valueStr); + } + else if (type == typeof(bool)) + { + result = bool.Parse(valueStr); + } + else if (type == typeof(float)) + { + result = float.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(decimal)) + { + result = decimal.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(double)) + { + result = double.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(sbyte)) + { + result = sbyte.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(byte)) + { + result = byte.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(short)) + { + result = short.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(ushort)) + { + result = ushort.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(int)) + { + result = int.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(uint)) + { + result = uint.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(long)) + { + result = long.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(ulong)) + { + result = ulong.Parse(valueStr, CultureInfo.InvariantCulture); + } +#if NET6_0 || NET7_0 || NET8_0 + else if (type == typeof(nint)) + { + result = nint.Parse(valueStr, CultureInfo.InvariantCulture); + } + else if (type == typeof(nuint)) + { + result = nuint.Parse(valueStr, CultureInfo.InvariantCulture); + } +#endif + else if (type == typeof(DateTime)) + { + if (valueStr.Equals("now")) + { + return DateTime.Now; + } + else if (valueStr.Equals("utcnow")) + { + return DateTime.UtcNow; + } + return DateTime.Parse(valueStr); + } + else + { + throw new ArgumentException("非预期值类型"); + } + + return result; + } } } diff --git a/Library/Utils/TypeHelper.cs b/Library/Utils/TypeHelper.cs new file mode 100644 index 0000000..dc7927d --- /dev/null +++ b/Library/Utils/TypeHelper.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; + +namespace Serein.Library.Utils +{ + /// + /// 类型转换工具类 + /// + public static class TypeHelper + { + + + public static string GetFriendlyName(this Type type,bool isFullName = true) + { + if (type.IsGenericType) + { + var builder = new StringBuilder(); + string typeName = isFullName? type.FullName : type.Name; + int backtickIndex = typeName.IndexOf('`'); + if (backtickIndex > 0) + { + typeName = typeName.Substring(0, backtickIndex); + } + + builder.Append(typeName); + builder.Append('<'); + + Type[] genericArgs = type.GetGenericArguments(); + for (int i = 0; i < genericArgs.Length; i++) + { + builder.Append(genericArgs[i].GetFriendlyName(isFullName)); + if (i < genericArgs.Length - 1) + builder.Append(", "); + } + + builder.Append('>'); + return builder.ToString(); + } + else if (type.IsArray) + { + return $"{type.GetElementType().GetFriendlyName()}[]"; + } + else + { + return TypeMap.TryGetValue(type, out var alias) ? alias : isFullName ? type.FullName : type.Name; ; + } + } + + private static readonly Dictionary TypeMap = new Dictionary + { + [typeof(int)] = "int", + [typeof(string)] = "string", + [typeof(bool)] = "bool", + [typeof(void)] = "void", + [typeof(object)] = "object", + [typeof(double)] = "double", + [typeof(float)] = "float", + [typeof(long)] = "long", + [typeof(byte)] = "byte", + [typeof(char)] = "char", + [typeof(decimal)] = "decimal", + [typeof(short)] = "short", + [typeof(uint)] = "uint", + [typeof(ulong)] = "ulong", + [typeof(ushort)] = "ushort", + [typeof(sbyte)] = "sbyte", + }; + + + + /// + /// 字面量转为对应类型 + /// + /// + /// + public static Type ToTypeOfString(this string valueStr) + { + if (valueStr.IndexOf('.') != -1) + { + // 通过指定的类型名称获取类型 + return Type.GetType(valueStr); + } + + + if (valueStr.Equals("bool", StringComparison.OrdinalIgnoreCase)) + { + return typeof(bool); + } + #region 整数型 + else if (valueStr.Equals("sbyte", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(SByte), StringComparison.OrdinalIgnoreCase)) + { + return typeof(SByte); + } + else if (valueStr.Equals("short", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(Int16), StringComparison.OrdinalIgnoreCase)) + { + return typeof(Int16); + } + else if (valueStr.Equals("int", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(Int32), StringComparison.OrdinalIgnoreCase)) + { + return typeof(Int32); + } + else if (valueStr.Equals("long", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(Int64), StringComparison.OrdinalIgnoreCase)) + { + return typeof(Int64); + } + + else if (valueStr.Equals("byte", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(Byte), StringComparison.OrdinalIgnoreCase)) + { + return typeof(Byte); + } + else if (valueStr.Equals("ushort", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(UInt16), StringComparison.OrdinalIgnoreCase)) + { + return typeof(UInt16); + } + else if (valueStr.Equals("uint", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(UInt32), StringComparison.OrdinalIgnoreCase)) + { + return typeof(UInt32); + } + else if (valueStr.Equals("ulong", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(UInt64), StringComparison.OrdinalIgnoreCase)) + { + return typeof(UInt64); + } + #endregion + + #region 浮点型 + else if (valueStr.Equals("float", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(Single), StringComparison.OrdinalIgnoreCase)) + { + return typeof(Single); + } + else if (valueStr.Equals("double", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(Double), StringComparison.OrdinalIgnoreCase)) + { + return typeof(Double); + } + #endregion + + #region 小数型 + + else if (valueStr.Equals("decimal", StringComparison.OrdinalIgnoreCase) + || valueStr.Equals(nameof(Decimal), StringComparison.OrdinalIgnoreCase)) + { + return typeof(Decimal); + } + #endregion + + #region 其他常见的类型 + else if (valueStr.Equals(nameof(DateTime), StringComparison.OrdinalIgnoreCase)) + { + return typeof(DateTime); + } + + else if (valueStr.Equals(nameof(String), StringComparison.OrdinalIgnoreCase)) + { + return typeof(String); + } + #endregion + + else + { + throw new ArgumentException($"无法解析的字面量类型[{valueStr}]"); + } + } + + + + + + } +} diff --git a/Workbench/Converters/CountToVisibilityConverter.cs b/Workbench/Converters/CountToVisibilityConverter.cs index 4a3d7ce..b72bc3e 100644 --- a/Workbench/Converters/CountToVisibilityConverter.cs +++ b/Workbench/Converters/CountToVisibilityConverter.cs @@ -10,9 +10,15 @@ using System.Windows; namespace Serein.Workbench.Converters { + /// + /// 将集合的元素数量转换为可见性。 + /// internal class CountToVisibilityConverter : IValueConverter { - public bool Inverse { get; set; } = false; // 可选:反转逻辑 + /// + /// 可选:是否反转逻辑。 + /// + public bool Inverse { get; set; } = false; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { diff --git a/Workbench/Converters/MethodDetailsSelectorConverter.cs b/Workbench/Converters/MethodDetailsSelectorConverter.cs index a5363f6..8138751 100644 --- a/Workbench/Converters/MethodDetailsSelectorConverter.cs +++ b/Workbench/Converters/MethodDetailsSelectorConverter.cs @@ -8,9 +8,12 @@ using System.Windows.Data; namespace Serein.Workbench.Converters { + /// + /// 选择方法详情的转换器 + /// internal class MethodDetailsSelectorConverter : IMultiValueConverter { - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { bool isShareParam = (bool)values[0]; var nodeDetails = values[1]; diff --git a/Workbench/Converters/TypeNameDisplaynConverter.cs b/Workbench/Converters/TypeNameDisplaynConverter.cs new file mode 100644 index 0000000..33f4d74 --- /dev/null +++ b/Workbench/Converters/TypeNameDisplaynConverter.cs @@ -0,0 +1,36 @@ +using Serein.Library.Utils; +using Serein.Workbench.Extension; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Serein.Workbench.Converters +{ + + /// + /// 类型名称显示转换器 + /// + internal class TypeNameDisplaynConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(value is Type type) + { + string typeName = type.GetFriendlyName(false); + return typeName; + } + else + { + return ""; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Workbench/Extension/MyExtension.cs b/Workbench/Extension/PointExtension.cs similarity index 55% rename from Workbench/Extension/MyExtension.cs rename to Workbench/Extension/PointExtension.cs index 5abc9ae..8b12a9b 100644 --- a/Workbench/Extension/MyExtension.cs +++ b/Workbench/Extension/PointExtension.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; namespace Serein.Workbench.Extension { @@ -44,34 +39,4 @@ namespace Serein.Workbench.Extension return new Vector(me.X, me.Y); } } - - /// - /// 向量(Vector)的扩展方法 - /// - public static class VectorExtension - { - /// - /// 计算两个向量的点积。 - /// - /// - /// - /// - public static double DotProduct(this Vector a, Vector b) - { - return a.X * b.X + a.Y * b.Y; - } - - /// - /// 计算两个向量的叉积。 - /// - /// - /// - public static Vector NormalizeTo(this Vector v) - { - var temp = v; - temp.Normalize(); - - return temp; - } - } } diff --git a/Workbench/Extension/VectorExtension.cs b/Workbench/Extension/VectorExtension.cs new file mode 100644 index 0000000..ffbab71 --- /dev/null +++ b/Workbench/Extension/VectorExtension.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Serein.Workbench.Extension +{ + + /// + /// 向量(Vector)的扩展方法 + /// + public static class VectorExtension + { + /// + /// 计算两个向量的点积。 + /// + /// + /// + /// + public static double DotProduct(this Vector a, Vector b) + { + return a.X * b.X + a.Y * b.Y; + } + + /// + /// 计算两个向量的叉积。 + /// + /// + /// + public static Vector NormalizeTo(this Vector v) + { + var temp = v; + temp.Normalize(); + + return temp; + } + } +} diff --git a/Workbench/Node/View/ActionNodeControl.xaml b/Workbench/Node/View/ActionNodeControl.xaml index 8466865..b150bc9 100644 --- a/Workbench/Node/View/ActionNodeControl.xaml +++ b/Workbench/Node/View/ActionNodeControl.xaml @@ -9,7 +9,7 @@ xmlns:themes="clr-namespace:Serein.Workbench.Themes" d:DataContext="{d:DesignInstance vm:ActionNodeControlViewModel}" mc:Ignorable="d" - MaxWidth="300"> + MaxWidth="500"> @@ -86,7 +86,7 @@ - + diff --git a/Workbench/Node/View/ConditionNodeControl.xaml b/Workbench/Node/View/ConditionNodeControl.xaml index 8c0184d..c4fdc68 100644 --- a/Workbench/Node/View/ConditionNodeControl.xaml +++ b/Workbench/Node/View/ConditionNodeControl.xaml @@ -8,7 +8,7 @@ xmlns:themes="clr-namespace:Serein.Workbench.Themes" d:DataContext="{d:DesignInstance vm:ConditionNodeControlViewModel}" mc:Ignorable="d" - MaxWidth="300"> + MaxWidth="500"> diff --git a/Workbench/Node/View/ExpOpNodeControl.xaml b/Workbench/Node/View/ExpOpNodeControl.xaml index 487b07f..8210724 100644 --- a/Workbench/Node/View/ExpOpNodeControl.xaml +++ b/Workbench/Node/View/ExpOpNodeControl.xaml @@ -7,7 +7,7 @@ xmlns:vm="clr-namespace:Serein.Workbench.Node.ViewModel" d:DataContext="{d:DesignInstance vm:ExpOpNodeControlViewModel}" mc:Ignorable="d" - MaxWidth="300"> + MaxWidth="500"> diff --git a/Workbench/Node/View/FlipflopNodeControl.xaml b/Workbench/Node/View/FlipflopNodeControl.xaml index 3f423d5..3b18d46 100644 --- a/Workbench/Node/View/FlipflopNodeControl.xaml +++ b/Workbench/Node/View/FlipflopNodeControl.xaml @@ -9,7 +9,7 @@ xmlns:themes="clr-namespace:Serein.Workbench.Themes" d:DataContext="{d:DesignInstance vm:FlipflopNodeControlViewModel}" mc:Ignorable="d" - MaxWidth="300"> + MaxWidth="500"> @@ -70,7 +70,7 @@ - + diff --git a/Workbench/Node/View/FlowCallNodeControl.xaml b/Workbench/Node/View/FlowCallNodeControl.xaml index 7ff62f7..ccbb1c2 100644 --- a/Workbench/Node/View/FlowCallNodeControl.xaml +++ b/Workbench/Node/View/FlowCallNodeControl.xaml @@ -9,7 +9,6 @@ xmlns:themes="clr-namespace:Serein.Workbench.Themes" mc:Ignorable="d" MaxWidth="300" - d:DataContext="{d:DesignInstance vm:FlowCallNodeControlViewModel}"> diff --git a/Workbench/Node/View/FlowCallNodeControl.xaml.cs b/Workbench/Node/View/FlowCallNodeControl.xaml.cs index 13a2322..b5bb6f7 100644 --- a/Workbench/Node/View/FlowCallNodeControl.xaml.cs +++ b/Workbench/Node/View/FlowCallNodeControl.xaml.cs @@ -38,14 +38,20 @@ namespace Serein.Workbench.Node.View ViewModel = viewModel; viewModel.NodeModel.DisplayName = "[流程接口]"; InitializeComponent(); - ViewModel.UploadMethodDetailsControl = UploadMethodDetailsControl; + ViewModel.UploadNode = UploadMethodDetailsControl; } - private void UploadMethodDetailsControl(MethodDetails methodDetails) + private void UploadMethodDetailsControl(IFlowNode? flowNode) { - //MethodDetailsControl.MethodDetails = methodDetails; - + if(flowNode is null) + { + this.MaxWidth = 300; + } + else + { + this.MaxWidth = 300; + } } /// diff --git a/Workbench/Node/View/GlobalDataControl.xaml b/Workbench/Node/View/GlobalDataControl.xaml index f46995b..34b464e 100644 --- a/Workbench/Node/View/GlobalDataControl.xaml +++ b/Workbench/Node/View/GlobalDataControl.xaml @@ -4,10 +4,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Serein.Workbench.Node.View" - xmlns:vm="clr-namespace:Serein.Workbench.Node.ViewModel" - d:DataContext="{d:DesignInstance vm:GlobalDataNodeControlViewModel}" - mc:Ignorable="d" - MaxWidth="300"> + xmlns:vm="clr-namespace:Serein.Workbench.Node.ViewModel" + d:DataContext="{d:DesignInstance vm:GlobalDataNodeControlViewModel}" + mc:Ignorable="d" + MaxWidth="500"> diff --git a/Workbench/Node/View/NetScriptNodeControl.xaml b/Workbench/Node/View/NetScriptNodeControl.xaml index b111715..01fba60 100644 --- a/Workbench/Node/View/NetScriptNodeControl.xaml +++ b/Workbench/Node/View/NetScriptNodeControl.xaml @@ -10,7 +10,7 @@ d:DataContext="{d:DesignInstance vm:NetScriptNodeControlViewModel}" mc:Ignorable="d" - MinWidth="50"> + MaxWidth="500"> diff --git a/Workbench/Node/View/ScriptNodeControl.xaml b/Workbench/Node/View/ScriptNodeControl.xaml index 732929b..989df5f 100644 --- a/Workbench/Node/View/ScriptNodeControl.xaml +++ b/Workbench/Node/View/ScriptNodeControl.xaml @@ -9,7 +9,7 @@ xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit" d:DataContext="{d:DesignInstance vm:ScriptNodeControlViewModel}" mc:Ignorable="d" - MinWidth="50"> + MaxWidth="500"> @@ -79,7 +79,7 @@ - + diff --git a/Workbench/Node/ViewModel/FlowCallNodeControlViewModel.cs b/Workbench/Node/ViewModel/FlowCallNodeControlViewModel.cs index ef1a794..ed76967 100644 --- a/Workbench/Node/ViewModel/FlowCallNodeControlViewModel.cs +++ b/Workbench/Node/ViewModel/FlowCallNodeControlViewModel.cs @@ -23,7 +23,7 @@ namespace Serein.Workbench.Node.ViewModel /// /// 刷新方法控件 /// - public Action UploadMethodDetailsControl; + public Action UploadNode; [ObservableProperty] @@ -105,9 +105,11 @@ namespace Serein.Workbench.Node.ViewModel { if(value is null) { + UploadNode?.Invoke(null); FlowCallNode.ResetTargetNode(); // 如果是不选择了,则重置一下 return; } + UploadNode.Invoke(value); FlowCallNode.SetTargetNode(value.Guid); // 重新设置目标节点 } diff --git a/Workbench/Serein.WorkBench.csproj b/Workbench/Serein.WorkBench.csproj index a597d11..21e22fc 100644 --- a/Workbench/Serein.WorkBench.csproj +++ b/Workbench/Serein.WorkBench.csproj @@ -11,7 +11,11 @@ true - + + + 1701;1702;1573;CS0414 + + @@ -28,6 +32,7 @@ + diff --git a/Workbench/Themes/MethodDetailsControl.xaml b/Workbench/Themes/MethodDetailsControl.xaml index 82d0a21..074594e 100644 --- a/Workbench/Themes/MethodDetailsControl.xaml +++ b/Workbench/Themes/MethodDetailsControl.xaml @@ -13,6 +13,7 @@ + @@ -21,18 +22,26 @@ + + + + + + + - + - - - - - - + + + + + + + - + @@ -144,6 +153,7 @@ +