|
@@ -12,21 +12,43 @@ namespace InABox.Core
|
|
|
private static Dictionary<string, Dictionary<string, IProperty>> _properties { get; }
|
|
|
= new Dictionary<string, Dictionary<string, IProperty>>();
|
|
|
|
|
|
- private static Dictionary<Type, List<IProperty>> _subObjects { get; } = new Dictionary<Type, List<IProperty>>();
|
|
|
+ private struct SubObject
|
|
|
+ {
|
|
|
+ public Type PropertyType { get; set; }
|
|
|
+
|
|
|
+ public string Name { get; set; }
|
|
|
+
|
|
|
+ public Action<object, object> Setter { get; set; }
|
|
|
+
|
|
|
+ public SubObject(Type objectType, Type propertyType, string name)
|
|
|
+ {
|
|
|
+ PropertyType = propertyType;
|
|
|
+ Name = name;
|
|
|
+ Setter = Expressions.Setter(objectType, name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Dictionary<Type, List<SubObject>> _subObjects { get; } = new Dictionary<Type, List<SubObject>>();
|
|
|
|
|
|
- private static List<IProperty> GetSubObjects(Type t)
|
|
|
+ private static List<SubObject>? GetSubObjects(Type t)
|
|
|
{
|
|
|
- return _subObjects.GetValueOrDefault(t) ?? new List<IProperty>();
|
|
|
+ CheckProperties(t);
|
|
|
+ return _subObjects.GetValueOrDefault(t);
|
|
|
}
|
|
|
|
|
|
public static void InitializeSubObjects(BaseObject obj)
|
|
|
{
|
|
|
- foreach(var linkProp in GetSubObjects(obj.GetType()))
|
|
|
+ var objs = GetSubObjects(obj.GetType());
|
|
|
+ if(objs is null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ foreach (var subObjectDef in objs)
|
|
|
{
|
|
|
- var subObj = (Activator.CreateInstance(linkProp.PropertyType) as ISubObject)!;
|
|
|
- linkProp.Setter()(subObj, subObj);
|
|
|
+ var subObj = (Activator.CreateInstance(subObjectDef.PropertyType) as ISubObject)!;
|
|
|
+ subObjectDef.Setter(obj, subObj);
|
|
|
subObj.SetLinkedParent(obj);
|
|
|
- subObj.SetLinkedPath(linkProp.Name);
|
|
|
+ subObj.SetLinkedPath(subObjectDef.Name);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -78,19 +100,18 @@ namespace InABox.Core
|
|
|
return editor;
|
|
|
}*/
|
|
|
|
|
|
- private static void RegisterSubObject(IProperty property)
|
|
|
+ private static void RegisterSubObject(Type objectType, Type propertyType, string name)
|
|
|
{
|
|
|
lock (_updatelock)
|
|
|
{
|
|
|
- var type = property.Parent?.PropertyType ?? property.ClassType;
|
|
|
- if(type != null)
|
|
|
+ if (!_subObjects.TryGetValue(objectType, out var properties))
|
|
|
{
|
|
|
- if (!_subObjects.TryGetValue(type, out var properties))
|
|
|
- {
|
|
|
- properties = new List<IProperty>();
|
|
|
- _subObjects[type] = properties;
|
|
|
- }
|
|
|
- properties.Add(property);
|
|
|
+ properties = new List<SubObject>();
|
|
|
+ _subObjects[objectType] = properties;
|
|
|
+ }
|
|
|
+ if (!properties.Any(x => x.Name == name && x.PropertyType == propertyType))
|
|
|
+ {
|
|
|
+ properties.Add(new SubObject(objectType, propertyType, name));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -194,20 +215,18 @@ namespace InABox.Core
|
|
|
Parent = parent,
|
|
|
Property = prop
|
|
|
};
|
|
|
- if (newProperty.IsEntityLink || newProperty.IsEnclosedEntity)
|
|
|
+
|
|
|
+ var isLink = prop.PropertyType.GetInterfaces().Contains(typeof(IEntityLink));
|
|
|
+ var isEnclosedEntity = prop.PropertyType.GetInterfaces().Contains(typeof(IEnclosedEntity));
|
|
|
+ var isBaseEditor = prop.PropertyType.Equals(typeof(BaseEditor)) ||
|
|
|
+ prop.PropertyType.IsSubclassOf(typeof(BaseEditor));
|
|
|
+ if ((isLink || isEnclosedEntity) && !isBaseEditor)
|
|
|
{
|
|
|
- RegisterSubObject(newProperty);
|
|
|
+ RegisterSubObject(type, prop.PropertyType, prop.Name);
|
|
|
}
|
|
|
|
|
|
- if (prop.PropertyType.GetInterfaces().Contains(typeof(IEntityLink)) ||
|
|
|
- prop.PropertyType.GetInterfaces().Contains(typeof(IEnclosedEntity)) ||
|
|
|
- prop.PropertyType.Equals(typeof(BaseEditor)) ||
|
|
|
- prop.PropertyType.IsSubclassOf(typeof(BaseEditor)))
|
|
|
+ if (isLink || isEnclosedEntity || isBaseEditor)
|
|
|
{
|
|
|
- if (prop.PropertyType.GetInterfaces().Contains(typeof(IEnclosedEntity)))
|
|
|
- {
|
|
|
- //RegisterProperty(newProperty);
|
|
|
- }
|
|
|
RegisterProperties(master, prop.PropertyType, name, newProperty);
|
|
|
}
|
|
|
else
|
|
@@ -255,11 +274,6 @@ namespace InABox.Core
|
|
|
//var dict = _Properties.GetOrAdd(entry.Class, className => new Dictionary<string, IProperty>());
|
|
|
//dict.TryAdd(entry.Name, entry);
|
|
|
}
|
|
|
-
|
|
|
- if (entry.IsEntityLink)
|
|
|
- {
|
|
|
- RegisterSubObject(entry);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
public static void Load(CustomProperty[] customproperties)
|