C#使用NugGet库验证字符串是否为linq表达式

tyu7yeag  于 2022-12-06  发布在  C#
关注(0)|答案(2)|浏览(122)

The string linq query can be entered dynamically, not only by developer. And it should be validated.
Do you have a regex expression or nuget to check if a string is a valid linq expression?
For example for a valid string linq expression :

(a.AccountId== 33
|| a.AccountId == 2
|| a.AccountId == 15) &&
(a.RoleId == 1||  a.RoleId == 3||  a.RoleId == 4)
  • Note - It can be also: (It can be each time a different linq query)
(a.TransactionId == 5 && a.EmployeeName == "Tony") || etc..

Example for string that can't be parsed:

(a.AccountId== 33
|| a.AccountId == 2
|| a.AccountId == 15)
(a.a.RoleId == 1||  a.RoleId == 3||  a.RoleId == 4)

Between those 2 , There is no Operator and you can see the a.a. which is invalid and can't be parsed to linq.

15)
(a.a.RoleId == 1||

If someone knows a good C# NuGet like ExpressionEvaluator for .net framework 4.5, Please let me know.
I have used ExpressionEvaluator, Dot net framework 4.5, But it says that this is a valid linq but it's not:

(a.AccountId== 33
|| a.AccountId == 2
|| a.AccountId == 15)
(a.a.RoleId == 1||  a.RoleId == 3||  a.RoleId == 4)

success is true, but it should be false.

success = new CompiledExpression(query);
  • Result of a NuGet or Regex

Inside the textbox, Will return Valid:

"(a.ProfileId == 5 && a.ProfileName == 'Alex')"

Invalid: - l.l double l.l is invalid

"l.l.LinkId == 5 || l.LinkName == 'Alex'"

valid and string can be parsed

"l.LinkId == 5 || l.LinkName == 'Alex'"

The parameter l. or a. can be changed to any A-Z I have tried to use DynamicExpresso.Core but i need to specify the parameter.

bwleehnv

bwleehnv1#

我已经使用动态Express库,创建了一个动态类与属性名称和属性类,通过右x =〉箭头函数参数和我的查询,他们动态类和它的工作. https://www.nuget.org/packages/DynamicExpresso.Core/

flvlnr44

flvlnr442#

如果我没理解错的话,您正在搜索使用“IN”关键字(SQL)的LINQ查询。相反,您可以在LINQ中使用Contains。

.NET服务器:

List<int> number = new List<int>{33,2,15};
from p in a
where p.AccountId.Contains(number)
select p

相关问题