1
This commit is contained in:
@@ -11,7 +11,6 @@ namespace BITKit
|
||||
/// </summary>
|
||||
public interface IProperty
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 属性接口
|
||||
@@ -71,11 +70,7 @@ namespace BITKit
|
||||
{
|
||||
foreach (var x in factory)
|
||||
{
|
||||
properties.Add(x.GetType()!.FullName, x);
|
||||
foreach (var att in x.GetType().GetCustomAttributes<CustomTypeAttribute>())
|
||||
{
|
||||
properties.Add(att.Type!.FullName, x);
|
||||
}
|
||||
AddPropertyInternal(x);
|
||||
}
|
||||
}
|
||||
Dictionary<string, object> properties=new();
|
||||
@@ -104,7 +99,8 @@ namespace BITKit
|
||||
}
|
||||
else
|
||||
{
|
||||
properties.Add(typeof(T).FullName, x = addFactory.Invoke());
|
||||
AddPropertyInternal(x =addFactory.Invoke());
|
||||
//properties.Add(typeof(T).FullName, x = addFactory.Invoke());
|
||||
return (T)x;
|
||||
}
|
||||
}
|
||||
@@ -132,17 +128,24 @@ namespace BITKit
|
||||
}
|
||||
public bool TrySetProperty<T>(T value)
|
||||
{
|
||||
if (properties.TryGetValue(typeof(T).FullName, out var x))
|
||||
bool result = false;
|
||||
foreach (var pair in properties.Where(x=>x.Value is T).ToArray())
|
||||
{
|
||||
properties[typeof(T).FullName] = value;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
properties[pair.Key] = value;
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
// if (properties.TryGetValue(typeof(T).FullName, out var x))
|
||||
// {
|
||||
// properties[typeof(T).FullName] = value;
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
public object[] GetProperties()=>properties.Values.ToArray();
|
||||
public object[] GetProperties()=>properties.Values.Distinct().ToArray();
|
||||
|
||||
public void Read(BinaryReader r)
|
||||
{
|
||||
@@ -168,9 +171,21 @@ namespace BITKit
|
||||
ClearProperties();
|
||||
foreach (var x in propertable.GetProperties())
|
||||
{
|
||||
properties.Add(x.GetType().FullName, x);
|
||||
AddPropertyInternal(x);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void AddPropertyInternal(object value)
|
||||
{
|
||||
if (value is ICloneable cloneable)
|
||||
{
|
||||
value = cloneable.Clone();
|
||||
}
|
||||
properties.Set(value.GetType().FullName, value);
|
||||
foreach (var att in value.GetType().GetCustomAttributes<CustomTypeAttribute>())
|
||||
{
|
||||
properties.Set(att.Type!.FullName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user