This commit is contained in:
CortexCore
2024-03-31 23:31:00 +08:00
parent e179d2eb53
commit b7b89ee71a
641 changed files with 31286 additions and 22134 deletions

View File

@@ -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);
}
}
}
}