mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Replaced DynamicLinq with DynamicExpresso
This commit is contained in:
parent
12ddcc3600
commit
caf2e3b2ae
@ -148,6 +148,10 @@
|
||||
<HintPath>..\packages\CUE.NET.1.0.3\lib\net45\CUE.NET.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="DynamicExpresso.Core, Version=1.3.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DynamicExpresso.Core.1.3.1.0\lib\net40\DynamicExpresso.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="GongSolutions.Wpf.DragDrop, Version=0.1.4.3, Culture=neutral, PublicKeyToken=d19974ea350ccea1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\gong-wpf-dragdrop.0.1.4.3\lib\net40\GongSolutions.Wpf.DragDrop.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@ -205,10 +209,6 @@
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Linq.Dynamic, Version=1.0.5840.25917, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Linq.Dynamic.1.0.6\lib\net40\System.Linq.Dynamic.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
|
||||
@ -1,12 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Dynamic;
|
||||
using System;
|
||||
using Artemis.Models.Interfaces;
|
||||
using Artemis.Utilities;
|
||||
using DynamicExpresso;
|
||||
|
||||
namespace Artemis.Models.Profiles
|
||||
{
|
||||
public class LayerConditionModel
|
||||
{
|
||||
private readonly Interpreter _interpreter;
|
||||
|
||||
public LayerConditionModel()
|
||||
{
|
||||
_interpreter = new Interpreter();
|
||||
}
|
||||
|
||||
public string Field { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Operator { get; set; }
|
||||
@ -22,15 +29,29 @@ namespace Artemis.Models.Profiles
|
||||
return false;
|
||||
|
||||
// Put the subject in a list, allowing Dynamic Linq to be used.
|
||||
var subjectList = new List<T> {(T) subject};
|
||||
bool res;
|
||||
if (Type == "String")
|
||||
res = subjectList.Where($"{Field}.ToLower() {Operator} @0", Value.ToLower()).Any();
|
||||
else if (Type == "Enum")
|
||||
res = subjectList.Where($"{Field} {Operator} \"{Value}\"").Any();
|
||||
else
|
||||
res = subjectList.Where($"{Field} {Operator} {Value}").Any();
|
||||
return res;
|
||||
{
|
||||
return _interpreter.Eval<bool>($"subject.{Field}.ToLower() {Operator} value",
|
||||
new Parameter("subject", typeof(T), subject),
|
||||
new Parameter("value", Value.ToLower()));
|
||||
}
|
||||
|
||||
Parameter rightParam = null;
|
||||
switch (Type)
|
||||
{
|
||||
case "Enum":
|
||||
var enumType = _interpreter.Eval<Type>($"subject.{Field}.GetType()", new Parameter("subject", typeof(T), subject));
|
||||
rightParam = new Parameter("value", Enum.Parse(enumType, Value));
|
||||
break;
|
||||
case "Boolean":
|
||||
rightParam = new Parameter("value", bool.Parse(Value));
|
||||
break;
|
||||
case "Int32":
|
||||
rightParam = new Parameter("value", int.Parse(Value));
|
||||
break;
|
||||
}
|
||||
|
||||
return _interpreter.Eval<bool>($"subject.{Field} {Operator} value", new Parameter("subject", typeof(T), subject), rightParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Artemis.Managers;
|
||||
using Artemis.Models;
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
<package id="Castle.Core" version="3.3.3" targetFramework="net452" />
|
||||
<package id="Colore" version="4.0.0" targetFramework="net452" />
|
||||
<package id="CUE.NET" version="1.0.3" targetFramework="net452" />
|
||||
<package id="DynamicExpresso.Core" version="1.3.1.0" targetFramework="net452" />
|
||||
<package id="Extended.Wpf.Toolkit" version="2.7" targetFramework="net452" />
|
||||
<package id="gong-wpf-dragdrop" version="0.1.4.3" targetFramework="net452" />
|
||||
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net452" />
|
||||
@ -20,7 +21,6 @@
|
||||
<package id="NLog" version="4.3.4" targetFramework="net452" />
|
||||
<package id="NLog.Schema" version="4.3.4" targetFramework="net452" />
|
||||
<package id="SpotifyAPI-NET" version="2.9.0" targetFramework="net452" />
|
||||
<package id="System.Linq.Dynamic" version="1.0.6" targetFramework="net452" />
|
||||
<package id="VirtualInput" version="1.0.1" targetFramework="net452" />
|
||||
<package id="WpfExceptionViewer" version="1.0.0.0" targetFramework="net452" />
|
||||
</packages>
|
||||
Loading…
x
Reference in New Issue
Block a user