Quellcode durchsuchen

Allowed for non-generic poster engine types.

Kenric Nugteren vor 11 Monaten
Ursprung
Commit
36087e40cc
1 geänderte Dateien mit 14 neuen und 6 gelöschten Zeilen
  1. 14 6
      InABox.Core/Postable/PosterUtils.cs

+ 14 - 6
InABox.Core/Postable/PosterUtils.cs

@@ -156,7 +156,8 @@ namespace InABox.Core
                 AppDomain.CurrentDomain.GetAssemblies(),
                 x => x.IsClass
                     && !x.IsAbstract
-                    && x.GetTypeInfo().GenericTypeParameters.Length == 1
+                    // Allow type-specific and generic engines
+                    && x.GetTypeInfo().GenericTypeParameters.Length <= 1
                     && x.HasInterface(typeof(IPosterEngine<,,>))
             ).Select(x =>
             {
@@ -197,13 +198,20 @@ namespace InABox.Core
             {
                 return Result.Error(new Exception("No poster for the given settings"));
             }
-            else if(engines.Count == 1)
-            {
-                return Result.Ok(engines[0].Engine.MakeGenericType(T));
-            }
             else
             {
-                return Result.Ok(engines.Single(x => x.Entity == T).Engine.MakeGenericType(T));
+                var engineType = engines.Count == 1 ? engines[0] : engines.Single(x => x.Entity == T);
+
+                if (engineType.Engine.IsGenericType)
+                {
+                    // If the engine is generic, we need to specify for the entity type.
+                    return Result.Ok(engineType.Engine.MakeGenericType(T));
+                }
+                else
+                {
+                    // If the engine has already been specified for a given entity type, we just return the engine type straight up.
+                    return Result.Ok(engineType.Engine);
+                }
             }
         }