Added generic type test to path resolve override

This commit is contained in:
Robert Beekman committed 2019-08-21 13:12:31 +02:00
1 parent 254a8e311f
commit d8e803c531
3 files changed
+25 -1

No files matched your search

+1
View File
@@ -116,6 +116,7 @@
<Compile Include="Extensions\DirectoryInfoExtensions.cs" />
<Compile Include="Extensions\RgbColorExtensions.cs" />
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
<Compile Include="Extensions\TypeExtensions.cs" />
<Compile Include="Models\DataModelDescription.cs" />
<Compile Include="Ninject\PluginSettingsProvider.cs" />
<Compile Include="Plugins\Abstract\ModuleDataModel.cs" />
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Artemis.Core.Extensions
{
public static class TypeExtensions
{
public static bool IsGenericType(this Type type, Type genericType)
{
if (type == null)
return false;
var baseType = type.BaseType;
if (baseType == null)
return false;
return baseType.GetGenericTypeDefinition() == genericType;
}
}
}
@@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
@@ -30,7 +31,7 @@ namespace Artemis.Plugins.Devices.Corsair
private void ResolveCorsairPath(object sender, ResolvePathEventArgs e)
{
if (e.RelativePart.Contains("Layouts\\Corsair"))
if (sender.GetType().IsGenericType(typeof(CorsairRGBDevice<>)))
{
// Start from the plugin directory
e.FinalPath = Path.Combine(PluginInfo.Directory.FullName, e.RelativePart, e.FileName);