74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using System.Security.Policy;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Deedy.Activity
|
|
{
|
|
public class ParamGroupAttribute : Attribute, IInitialSortable
|
|
{
|
|
protected internal ParamGroupAttribute() { }
|
|
public ParamGroupAttribute(string groupName, int initialSort = 0, bool canAddNew = false)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(groupName)) throw new ArgumentNullException("参数分组名称不可为「null」或「空白字符」");
|
|
if (groupName == RuntimeParams || groupName == WorkingParams || groupName == DefaultParams) throw new ArgumentException("不可以用系统保留名称做为自定义分组名称...");
|
|
this.GroupName = groupName;
|
|
this.InitialSort = initialSort;
|
|
this.CanAddNew = canAddNew;
|
|
}
|
|
public const string RuntimeParams = "系统参数";
|
|
public const string WorkingParams = "工作参数";
|
|
public const string DefaultParams = "其它参数";
|
|
public int InitialSort { get; set; } = 0;
|
|
private string _GroupName = "";
|
|
public string GroupName
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrEmpty(_GroupName)) _GroupName = DefaultParams;
|
|
return _GroupName;
|
|
}
|
|
private set
|
|
{
|
|
if (value == _GroupName) return;
|
|
if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(value.Trim())) _GroupName = DefaultParams;
|
|
else _GroupName = value;
|
|
}
|
|
}
|
|
[AllowNull]
|
|
private string _Description;
|
|
|
|
public string Description
|
|
{
|
|
get { return string.IsNullOrEmpty(_Description) ? _GroupName : _Description; }
|
|
set { _Description = string.IsNullOrEmpty(value) ? _GroupName : value; }
|
|
}
|
|
|
|
public bool CanAddNew { get; protected internal set; }
|
|
|
|
public ParamDefineCollection Params { get; protected internal set; } = [];
|
|
|
|
internal static ParamGroupAttribute CreateRuntimeGroup() => new()
|
|
{
|
|
GroupName = RuntimeParams,
|
|
Description = "运行时需要的参数,自定义参数尽量不要放置到此分组中...",
|
|
InitialSort = int.MinValue
|
|
};
|
|
internal static ParamGroupAttribute CreateWorkingGroup() => new()
|
|
{
|
|
GroupName = WorkingParams,
|
|
Description = "动作执行时的工作逻辑所需要的参数",
|
|
InitialSort = int.MinValue + 1
|
|
};
|
|
internal static ParamGroupAttribute CreateDefaultGroup() => new()
|
|
{
|
|
GroupName = DefaultParams,
|
|
Description = "所有未分组参数均会被默认放置到此分组中",
|
|
InitialSort = int.MaxValue
|
|
};
|
|
}
|
|
}
|