Loading Nocube.Common/Extensions.cs +32 −1 Original line number Diff line number Diff line using Nocube.Common.Nodes; using Nocube.Common.Properties; namespace Nocube.Common; public static class StringExtensions Loading @@ -6,7 +9,15 @@ public static class StringExtensions { public IMarker AsMarker() { return new Marker(s.GetHashCode()); return new Marker(s.GetStableHashCode()); } public int GetStableHashCode() { unchecked { return s.Aggregate(17, (current, c) => current * 31 + c); } } } } Loading Loading @@ -45,3 +56,23 @@ public static class ConvExtensions } } } public static class FunctionExtensions { extension<T>(T any) where T : Function { public void AddExecute() { any.AddToProperties(new ExecuteProperty()); } } } public static class MarkerableExtensions { extension(IMarkerable mark) { public bool MarkEqual(IMarker marker) => mark.Mark.MarkId == marker.MarkId; } } No newline at end of file Nocube.Common/IMarker.cs +12 −0 Original line number Diff line number Diff line Loading @@ -23,3 +23,15 @@ public interface IMarker /// </summary> int MarkId { get; } } // ReSharper disable once IdentifierTypo public interface IMarkerable<out T> : IMarkerable where T : IMarker? { T Mark { get; } } public interface IMarkerable { IMarker Mark { get; } } No newline at end of file Nocube.Common/Nodes/Function.cs +3 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ namespace Nocube.Common.Nodes; /// <summary> /// 一个节点函数的抽象类,继承<see cref="INode"/>,提供了构建节点的通用功能。 /// </summary> public abstract class Function : IFunction public abstract class Function : IFunction, IMarkerable { /// <summary> /// 函数名称。 Loading Loading @@ -44,6 +44,8 @@ public abstract class Function : IFunction { PropertiesList.Add(new ExecuteProperty()); } public IMarker Mark => (Name + Description).AsMarker(); } public abstract class FunctionByName<T> : Function Loading Nocube.Common/Properties/IProperty.cs +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ public interface IProperty<T> : IProperty /// <summary> /// 表示一个带有基类型数据的属性 /// </summary> public interface IProperty : IName, IDescription public interface IProperty : IName, IDescription, IMarkerable { /// <summary> /// 属性承载的基类属性 Loading Nocube.Common/Properties/Property.cs +18 −3 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ namespace Nocube.Common.Properties; /// <param name="description">属性的描述</param> /// <param name="direct">指定属性数据的流向</param> /// <typeparam name="T">属性数据类型</typeparam> public class Property<T>(string name, string description, FlowDirect direct) : IProperty<T> public class Property<T>(string name, string description, FlowDirect direct, IMarker? marker = null) : IProperty<T> { /// <inheritdoc/> public string Name { get; } = name; Loading @@ -29,18 +29,28 @@ public class Property<T>(string name, string description, FlowDirect direct) : I get => Data; set => Data = (T?)value; } /// <summary> /// 属性标记器,构造时为空则生成一个Marker。 /// </summary> public IMarker Mark => marker ?? (Name + Description).AsMarker(); } public class AnyProperty(string name = "Any", string desc = "此属性接受任意类型的输入。") : IAnyProperty public class AnyProperty(string name = "Any", string desc = "此属性接受任意类型的输入。", IMarker? marker = null) : IAnyProperty { public string Name { get; } = name; public string Description { get; } = desc; public object? Data { get; set; } public Type ArrowType { get; } = typeof(object); public FlowDirect Direct => FlowDirect.Any; /// <summary> /// 属性标记器,构造时为空则生成一个Marker。 /// </summary> public IMarker Mark => marker ?? (Name + Description).AsMarker(); } public class VoidProperty(string name = "Void", string desc = "此属性接受任意类型的输入,但无法传递数据。") : IVoidProperty public class VoidProperty(string name = "Void", string desc = "此属性接受任意类型的输入,但无法传递数据。", IMarker? marker = null) : IVoidProperty { public string Name { get; } = name; public string Description { get; } = desc; Loading @@ -52,6 +62,11 @@ public class VoidProperty(string name = "Void", string desc = "此属性接受 public Type ArrowType { get; } = typeof(void); public FlowDirect Direct => FlowDirect.Any; /// <summary> /// 属性标记器,构造时为空则生成一个Marker。 /// </summary> public IMarker Mark => marker ?? (Name + Description).AsMarker(); } public class ExecuteProperty() Loading Loading
Nocube.Common/Extensions.cs +32 −1 Original line number Diff line number Diff line using Nocube.Common.Nodes; using Nocube.Common.Properties; namespace Nocube.Common; public static class StringExtensions Loading @@ -6,7 +9,15 @@ public static class StringExtensions { public IMarker AsMarker() { return new Marker(s.GetHashCode()); return new Marker(s.GetStableHashCode()); } public int GetStableHashCode() { unchecked { return s.Aggregate(17, (current, c) => current * 31 + c); } } } } Loading Loading @@ -45,3 +56,23 @@ public static class ConvExtensions } } } public static class FunctionExtensions { extension<T>(T any) where T : Function { public void AddExecute() { any.AddToProperties(new ExecuteProperty()); } } } public static class MarkerableExtensions { extension(IMarkerable mark) { public bool MarkEqual(IMarker marker) => mark.Mark.MarkId == marker.MarkId; } } No newline at end of file
Nocube.Common/IMarker.cs +12 −0 Original line number Diff line number Diff line Loading @@ -23,3 +23,15 @@ public interface IMarker /// </summary> int MarkId { get; } } // ReSharper disable once IdentifierTypo public interface IMarkerable<out T> : IMarkerable where T : IMarker? { T Mark { get; } } public interface IMarkerable { IMarker Mark { get; } } No newline at end of file
Nocube.Common/Nodes/Function.cs +3 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ namespace Nocube.Common.Nodes; /// <summary> /// 一个节点函数的抽象类,继承<see cref="INode"/>,提供了构建节点的通用功能。 /// </summary> public abstract class Function : IFunction public abstract class Function : IFunction, IMarkerable { /// <summary> /// 函数名称。 Loading Loading @@ -44,6 +44,8 @@ public abstract class Function : IFunction { PropertiesList.Add(new ExecuteProperty()); } public IMarker Mark => (Name + Description).AsMarker(); } public abstract class FunctionByName<T> : Function Loading
Nocube.Common/Properties/IProperty.cs +1 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ public interface IProperty<T> : IProperty /// <summary> /// 表示一个带有基类型数据的属性 /// </summary> public interface IProperty : IName, IDescription public interface IProperty : IName, IDescription, IMarkerable { /// <summary> /// 属性承载的基类属性 Loading
Nocube.Common/Properties/Property.cs +18 −3 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ namespace Nocube.Common.Properties; /// <param name="description">属性的描述</param> /// <param name="direct">指定属性数据的流向</param> /// <typeparam name="T">属性数据类型</typeparam> public class Property<T>(string name, string description, FlowDirect direct) : IProperty<T> public class Property<T>(string name, string description, FlowDirect direct, IMarker? marker = null) : IProperty<T> { /// <inheritdoc/> public string Name { get; } = name; Loading @@ -29,18 +29,28 @@ public class Property<T>(string name, string description, FlowDirect direct) : I get => Data; set => Data = (T?)value; } /// <summary> /// 属性标记器,构造时为空则生成一个Marker。 /// </summary> public IMarker Mark => marker ?? (Name + Description).AsMarker(); } public class AnyProperty(string name = "Any", string desc = "此属性接受任意类型的输入。") : IAnyProperty public class AnyProperty(string name = "Any", string desc = "此属性接受任意类型的输入。", IMarker? marker = null) : IAnyProperty { public string Name { get; } = name; public string Description { get; } = desc; public object? Data { get; set; } public Type ArrowType { get; } = typeof(object); public FlowDirect Direct => FlowDirect.Any; /// <summary> /// 属性标记器,构造时为空则生成一个Marker。 /// </summary> public IMarker Mark => marker ?? (Name + Description).AsMarker(); } public class VoidProperty(string name = "Void", string desc = "此属性接受任意类型的输入,但无法传递数据。") : IVoidProperty public class VoidProperty(string name = "Void", string desc = "此属性接受任意类型的输入,但无法传递数据。", IMarker? marker = null) : IVoidProperty { public string Name { get; } = name; public string Description { get; } = desc; Loading @@ -52,6 +62,11 @@ public class VoidProperty(string name = "Void", string desc = "此属性接受 public Type ArrowType { get; } = typeof(void); public FlowDirect Direct => FlowDirect.Any; /// <summary> /// 属性标记器,构造时为空则生成一个Marker。 /// </summary> public IMarker Mark => marker ?? (Name + Description).AsMarker(); } public class ExecuteProperty() Loading