1
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user