This commit is contained in:
CortexCore
2025-02-24 23:02:43 +08:00
parent 41715e4413
commit 8261a458e2
105 changed files with 2934 additions and 696 deletions

View File

@@ -14,6 +14,22 @@ namespace BITKit
}
public class ValueWrapper<T> : IWrapper<T>
{
public ValueWrapper()
{
var type = typeof(T);
if (type == typeof(string))
{
_value = string.Empty.As<T>();
return;
}
if(type.IsAbstract || type.IsInterface)return;
// 检查类型是否具有公共无参数构造函数
var constructor = type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null);
if (constructor is not null)
{
_value = Activator.CreateInstance<T>();
}
}
public Action<T, T> OnValueChanged { get; set; }
public T Value
@@ -27,7 +43,7 @@ namespace BITKit
}
}
private T _value = typeof(T) == typeof(string) ? string.Empty.As<T>() : Activator.CreateInstance<T>();
private T _value;
public object Obj
{
get => Value;