|
@@ -112,6 +112,44 @@ namespace InABox.Core
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private static Dictionary<string, Tuple<Type, Type>>? _formInstanceTypes;
|
|
|
+ private static Dictionary<string, Tuple<Type, Type>> FormInstanceTypes
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ _formInstanceTypes ??= CoreUtils.TypeList(
|
|
|
+ AppDomain.CurrentDomain.GetAssemblies(),
|
|
|
+ x => !x.IsAbstract && x.GetInterfaces().Contains(typeof(IDigitalFormInstance))
|
|
|
+ ).Select(x =>
|
|
|
+ {
|
|
|
+ var inter = x.GetInterfaces()
|
|
|
+ .Where(x => x.IsGenericType && x.GetGenericTypeDefinition().Equals(typeof(IDigitalFormInstance<>))).FirstOrDefault();
|
|
|
+ if (inter != null)
|
|
|
+ {
|
|
|
+ var link = inter.GenericTypeArguments[0];
|
|
|
+ var entityLinkDef = link.GetSuperclassDefinition(typeof(EntityLink<>));
|
|
|
+ if (entityLinkDef != null)
|
|
|
+ {
|
|
|
+ var entityType = entityLinkDef.GenericTypeArguments[0];
|
|
|
+ return new Tuple<string, Type, Type>(entityType.Name, x, entityType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }).Where(x => x != null).ToDictionary(x => x!.Item1, x => new Tuple<Type, Type>(x!.Item2, x!.Item3));
|
|
|
+ return _formInstanceTypes;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Type? GetFormInstanceType(string appliesTo)
|
|
|
+ {
|
|
|
+ if (FormInstanceTypes.TryGetValue(appliesTo, out var result))
|
|
|
+ {
|
|
|
+ return result.Item1;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private static Dictionary<Type, IEntityFormUtils> _formUtils = new Dictionary<Type, IEntityFormUtils>();
|
|
|
|
|
|
public static void AddFormUtils<TForm, TEntity, TEntityLink>(
|