From 7761ab4e6527945c4c66d08cb3ce38cca3115e22 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 20 Jun 2015 17:55:37 +0200 Subject: [PATCH] Enabled Logic objects for plugins --- Logic/Support/SingularFactory.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Logic/Support/SingularFactory.cs b/Logic/Support/SingularFactory.cs index 712cdf3a..3fad6d27 100644 --- a/Logic/Support/SingularFactory.cs +++ b/Logic/Support/SingularFactory.cs @@ -47,8 +47,22 @@ namespace Swarmops.Logic.Support } if (logicTypes.Length == 0) { - throw new InvalidOperationException ( - "Unable to find higher-order class in Swarmops.Logic for base type " + basicType.ToString()); + // There are no matching types in Swarmops.Logic; look through ALL loaded assemblies, as it may be in a plugin. + + foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + logicTypes = assembly.GetTypes().Where(type => type.IsSubclassOf(basicType)).ToArray(); + if (logicTypes.Length == 1) + { + break; + } + } + + if (logicTypes.Length == 0) + { + throw new InvalidOperationException ( + "Unable to find higher-order class in Swarmops.Logic for base type " + basicType.ToString()); + } } Type logicType = logicTypes[0]; @@ -58,7 +72,7 @@ namespace Swarmops.Logic.Support if (basicConverterMethod == null) { throw new InvalidOperationException( - "Unable to find a public static method named \"" + logicType.ToString() + ".FromBasic (" +basicType.ToString()+ ")\" in the Swarmops.Logic assembly"); + "Unable to find a public static method named \"" + logicType.ToString() + ".FromBasic (" +basicType.ToString()+ ")\" in a loaded assembly"); } _converterLookup[basicType] = basicConverterMethod;