浏览代码

test

develop
Robin Thoni 6 年前
父节点
当前提交
429843681d
共有 24 个文件被更改,包括 846 次插入408 次删除
  1. 16
    14
      .idea/.idea.luticate2/.idea/contentModel.xml
  2. 1
    0
      .idea/.idea.luticate2/.idea/indexLayout.xml
  3. 12
    0
      .idea/httpRequests/2018-07-16T013928.404.html
  4. 7
    0
      .idea/httpRequests/http-requests-log.http
  5. 1
    1
      Luticate2.Auth.ConsoleSample/Commands/ListCommand.cs
  6. 32
    20
      Luticate2.Auth.ConsoleSample/Program.cs
  7. 191
    0
      Luticate2.Auth.Tests/Business/Fields/LuDboModelExpressionConverterTests.cs
  8. 0
    135
      Luticate2.Auth.Tests/Business/FieldsExpressions/LuFieldsExpressionsTests.cs
  9. 155
    22
      Luticate2.Auth.Tests/RandomTests.cs
  10. 36
    0
      Luticate2.Auth/Business/Auth/DMEC/LuDMECGroupsToModel.cs
  11. 0
    37
      Luticate2.Auth/Business/Auth/FieldsExpressions/LuFieldsExpressionsLuGroupDboLuGroups.cs
  12. 0
    36
      Luticate2.Auth/Business/Auth/FieldsExpressions/LuFieldsExpressionsLuMetadataDboLuMetadata.cs
  13. 46
    46
      Luticate2.Auth/Business/Crud/LuEfCrudBusiness.cs
  14. 58
    0
      Luticate2.Auth/Business/Fields/DMEC/LuExpressionConverterEnumerable.cs
  15. 38
    0
      Luticate2.Auth/Business/Fields/DMEC/LuExpressionConverterIdentity.cs
  16. 9
    0
      Luticate2.Auth/Business/Fields/DMEC/LuExpressionConverterOptions.cs
  17. 35
    0
      Luticate2.Auth/Business/Fields/DMEC/LuExpressionConverterStaticMethods.cs
  18. 96
    0
      Luticate2.Auth/Business/Fields/LuExpressionConverter.cs
  19. 88
    0
      Luticate2.Auth/Business/Fields/LuExpressionConverterVisitor.cs
  20. 0
    24
      Luticate2.Auth/Business/FieldsExpressions/Basic/LuFieldsExpressionsString.cs
  21. 0
    60
      Luticate2.Auth/Business/FieldsExpressions/LuFieldsExpressions.cs
  22. 5
    1
      Luticate2.Auth/Business/Pagination/LuFilterParser.cs
  23. 20
    0
      Luticate2.Auth/Interfaces/ILuExpressionConverter.cs
  24. 0
    12
      Luticate2.Auth/Interfaces/ILuFieldsExpressions.cs

+ 16
- 14
.idea/.idea.luticate2/.idea/contentModel.xml 查看文件

@@ -1,7 +1,10 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3 3
   <component name="ContentModelStore">
4
-    <e p="$USER_HOME$/.Rider2018.1/system/resharper-host/local/Transient/ReSharperHost/v12/SolutionCaches/_luticate2.1484521948.00" t="ExcludeRecursive" />
4
+    <e p="$APPLICATION_CONFIG_DIR$/consoles/db" t="IncludeRecursive" />
5
+    <e p="$APPLICATION_CONFIG_DIR$/extensions" t="IncludeRecursive" />
6
+    <e p="$USER_HOME$/.Rider2018.2/system/extResources" t="IncludeRecursive" />
7
+    <e p="$USER_HOME$/.Rider2018.2/system/resharper-host/local/Transient/ReSharperHost/v182/SolutionCaches/_luticate2.1484521948.00" t="ExcludeRecursive" />
5 8
     <e p="$USER_HOME$/.nuget/packages/xunit.runner.visualstudio/2.3.1/build/netcoreapp1.0/xunit.runner.reporters.netcoreapp10.dll" t="Include" />
6 9
     <e p="$USER_HOME$/.nuget/packages/xunit.runner.visualstudio/2.3.1/build/netcoreapp1.0/xunit.runner.utility.netcoreapp10.dll" t="Include" />
7 10
     <e p="$USER_HOME$/.nuget/packages/xunit.runner.visualstudio/2.3.1/build/netcoreapp1.0/xunit.runner.visualstudio.dotnetcore.testadapter.dll" t="Include" />
@@ -10,9 +13,8 @@
10 13
       <e p="Luticate2.Auth" t="IncludeRecursive">
11 14
         <e p="Business" t="Include">
12 15
           <e p="Auth" t="Include">
13
-            <e p="FieldsExpressions" t="Include">
14
-              <e p="LuFieldsExpressionsLuGroupDboLuGroups.cs" t="Include" />
15
-              <e p="LuFieldsExpressionsLuMetadataDboLuMetadata.cs" t="Include" />
16
+            <e p="DMEC" t="Include">
17
+              <e p="LuDMECGroupsToModel.cs" t="Include" />
16 18
             </e>
17 19
             <e p="LuGroupsBusiness.cs" t="Include" />
18 20
             <e p="PartialObjectCopier" t="Include">
@@ -25,15 +27,17 @@
25 27
             <e p="LuEfCrudBusiness.cs" t="Include" />
26 28
           </e>
27 29
           <e p="Fields" t="Include">
30
+            <e p="DMEC" t="Include">
31
+              <e p="LuExpressionConverterEnumerable.cs" t="Include" />
32
+              <e p="LuExpressionConverterIdentity.cs" t="Include" />
33
+              <e p="LuExpressionConverterOptions.cs" t="Include" />
34
+              <e p="LuExpressionConverterStaticMethods.cs" t="Include" />
35
+            </e>
36
+            <e p="LuExpressionConverter.cs" t="Include" />
37
+            <e p="LuExpressionConverterVisitor.cs" t="Include" />
28 38
             <e p="LuFieldsExtensions.cs" t="Include" />
29 39
             <e p="LuPartialFieldsParser.cs" t="Include" />
30 40
           </e>
31
-          <e p="FieldsExpressions" t="Include">
32
-            <e p="Basic" t="Include">
33
-              <e p="LuFieldsExpressionsString.cs" t="Include" />
34
-            </e>
35
-            <e p="LuFieldsExpressions.cs" t="Include" />
36
-          </e>
37 41
           <e p="LuExpressionUtils.cs" t="Include" />
38 42
           <e p="Pagination" t="Include">
39 43
             <e p="LuFilterParser.cs" t="Include" />
@@ -94,7 +98,7 @@
94 98
         </e>
95 99
         <e p="Interfaces" t="Include">
96 100
           <e p="ILuCrud.cs" t="Include" />
97
-          <e p="ILuFieldsExpressions.cs" t="Include" />
101
+          <e p="ILuExpressionConverter.cs" t="Include" />
98 102
           <e p="ILuOrderByObjectType.cs" t="Include" />
99 103
           <e p="ILuPartialObjectCopier.cs" t="Include" />
100 104
         </e>
@@ -128,11 +132,9 @@
128 132
       <e p="Luticate2.Auth.Tests" t="IncludeRecursive">
129 133
         <e p="Business" t="Include">
130 134
           <e p="Fields" t="Include">
135
+            <e p="LuDboModelExpressionConverterTests.cs" t="Include" />
131 136
             <e p="LuFieldDboTests.cs" t="Include" />
132 137
           </e>
133
-          <e p="FieldsExpressions" t="Include">
134
-            <e p="LuFieldsExpressionsTests.cs" t="Include" />
135
-          </e>
136 138
           <e p="LuExpressionUtilsTests.cs" t="Include" />
137 139
           <e p="Pagination" t="Include">
138 140
             <e p="LuFilterTests.cs" t="Include" />

+ 1
- 0
.idea/.idea.luticate2/.idea/indexLayout.xml 查看文件

@@ -1,6 +1,7 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3 3
   <component name="ContentModelUserStore">
4
+    <attachedFolders />
4 5
     <explicitIncludes />
5 6
     <explicitExcludes />
6 7
   </component>

+ 12
- 0
.idea/httpRequests/2018-07-16T013928.404.html 查看文件

@@ -0,0 +1,12 @@
1
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
2
+<html>
3
+<head>
4
+    <title>404 Not Found</title>
5
+</head>
6
+<body>
7
+<h1>Not Found</h1>
8
+<p>The requested URL /api/item was not found on this server.</p>
9
+<hr>
10
+<address>Apache/2.4.29 (Ubuntu) Server at localhost Port 80</address>
11
+</body>
12
+</html>

+ 7
- 0
.idea/httpRequests/http-requests-log.http 查看文件

@@ -0,0 +1,7 @@
1
+GET http://localhost:80/api/item
2
+Accept: application/json
3
+
4
+<> 2018-07-16T013928.404.html
5
+
6
+###
7
+

+ 1
- 1
Luticate2.Auth.ConsoleSample/Commands/ListCommand.cs 查看文件

@@ -54,7 +54,7 @@ namespace Luticate2.Auth.ConsoleSample.Commands
54 54
                 }
55 55
                 var partialResponse = partialResponseResult.Data;
56 56
 
57
-                var filterResult = LuFilterParser.Parse<LuGroups>(Filter);
57
+                var filterResult = LuFilterParser.Parse<LuGroupDbo>(Filter);
58 58
                 if (!filterResult)
59 59
                 {
60 60
                     filterResult.WriteLineError();

+ 32
- 20
Luticate2.Auth.ConsoleSample/Program.cs 查看文件

@@ -1,12 +1,9 @@
1 1
 using System;
2
+using System.Collections.Generic;
2 3
 using Luticate2.Auth.Business.Auth;
3
-using Luticate2.Auth.Business.Auth.FieldsExpressions;
4
+using Luticate2.Auth.Business.Auth.DMEC;
4 5
 using Luticate2.Auth.Business.Auth.PartialObjectCopier;
5
-using Luticate2.Auth.Business.FieldsExpressions;
6
-using Luticate2.Auth.Business.FieldsExpressions.Basic;
7
-//using Luticate2.Auth.Business.Pagination.OrderBy;
8
-//using Luticate2.Auth.Business.Pagination.OrderBy.Basic;
9
-using Luticate2.Auth.Business.PartialObjectCopier;
6
+using Luticate2.Auth.Business.Fields.DMEC;
10 7
 using Luticate2.Auth.ConsoleSample.Commands;
11 8
 using Luticate2.Auth.DataAccess;
12 9
 using Luticate2.Auth.DataAccess.Models;
@@ -14,6 +11,7 @@ using Luticate2.Auth.Dbo.Auth;
14 11
 using Luticate2.Auth.Interfaces;
15 12
 using Microsoft.EntityFrameworkCore;
16 13
 using Microsoft.Extensions.DependencyInjection;
14
+using Microsoft.Extensions.DependencyInjection.Extensions;
17 15
 using NClap.Metadata;
18 16
 using NClap.Repl;
19 17
 
@@ -34,6 +32,13 @@ namespace Luticate2.Auth.ConsoleSample
34 32
     class Program
35 33
     {
36 34
         public static IServiceProvider ServiceProvider;
35
+
36
+        protected static void AddILuExpressionConverter<TTypeFrom, TTypeTo, TTypeImpl>(IServiceCollection services)
37
+            where TTypeImpl : class, ILuExpressionConverter<TTypeFrom, TTypeTo>
38
+        {
39
+            services.AddSingleton<ILuExpressionConverter<TTypeFrom, TTypeTo>, TTypeImpl>();
40
+            services.TryAddSingleton<ILuExpressionConverter<TTypeFrom>, TTypeImpl>();
41
+        }
37 42
         
38 43
         static void Main(string[] args)
39 44
         {
@@ -46,22 +51,29 @@ namespace Luticate2.Auth.ConsoleSample
46 51
             services.AddSingleton<ILuPartialObjectCopier<LuGroupDbo, LuGroups>, LuPOCGroupsToModel>();
47 52
 
48 53
 
49
-            services.AddSingleton<ILuFieldsExpressions<LuObjectsMetadataDbo, LuObjectsMetadata>, LuFieldsExpressionsLuMetadataDboLuMetadata>();
50
-            services.AddSingleton<ILuFieldsExpressions<LuGroupDbo, LuGroups>, LuFieldsExpressionsLuGroupDboLuGroups>();
51
-
52
-            services.AddSingleton<ILuFieldsExpressions<string, string>, LuFieldsExpressionsString>();
53
-            services.AddSingleton<ILuFieldsExpressions<int, int>, LuFieldsExpressions<int, int>>();
54
-            services.AddSingleton<ILuFieldsExpressions<Guid, Guid>, LuFieldsExpressions<Guid, Guid>>();
54
+//            services.AddSingleton<ILuDboModelExpressionConverter<TestDbo1, TestModel1>, LuDMECTest1>();
55
+            AddILuExpressionConverter<LuGroupDbo, LuGroups, LuDMECGroupsToModel>(services);
56
+            AddILuExpressionConverter<string, string, LuExpressionConverterIdentity<string>>(services);
57
+            AddILuExpressionConverter<Guid, Guid, LuExpressionConverterIdentity<Guid>>(services);
58
+            AddILuExpressionConverter<bool, bool, LuExpressionConverterIdentity<bool>>(services);
55 59
 
56
-            services.AddSingleton<ILuFieldsExpressions<DateTime, DateTime>, LuFieldsExpressions<DateTime, DateTime>>();
57
-            services.AddSingleton<ILuFieldsExpressions<DateTimeOffset, DateTimeOffset>, LuFieldsExpressions<DateTimeOffset, DateTimeOffset>>();
58
-            services.AddSingleton<ILuFieldsExpressions<DateTime, DateTimeOffset>, LuFieldsExpressions<DateTime, DateTimeOffset>>();
59
-            services.AddSingleton<ILuFieldsExpressions<DateTimeOffset, DateTime>, LuFieldsExpressions<DateTimeOffset, DateTime>>();
60 60
 
61
-            services.AddSingleton<ILuFieldsExpressions<DateTime?, DateTime?>, LuFieldsExpressions<DateTime?, DateTime?>>();
62
-            services.AddSingleton<ILuFieldsExpressions<DateTimeOffset?, DateTimeOffset?>, LuFieldsExpressions<DateTimeOffset?, DateTimeOffset?>>();
63
-            services.AddSingleton<ILuFieldsExpressions<DateTime?, DateTimeOffset?>, LuFieldsExpressions<DateTime?, DateTimeOffset?>>();
64
-            services.AddSingleton<ILuFieldsExpressions<DateTimeOffset?, DateTime?>, LuFieldsExpressions<DateTimeOffset?, DateTime?>>();
61
+//            services.AddSingleton<ILuFieldsExpressions<LuObjectsMetadataDbo, LuObjectsMetadata>, LuFieldsExpressionsLuMetadataDboLuMetadata>();
62
+//            services.AddSingleton<ILuFieldsExpressions<LuGroupDbo, LuGroups>, LuFieldsExpressionsLuGroupDboLuGroups>();
63
+//
64
+//            services.AddSingleton<ILuFieldsExpressions<string, string>, LuFieldsExpressionsString>();
65
+//            services.AddSingleton<ILuFieldsExpressions<int, int>, LuFieldsExpressions<int, int>>();
66
+//            services.AddSingleton<ILuFieldsExpressions<Guid, Guid>, LuFieldsExpressions<Guid, Guid>>();
67
+//
68
+//            services.AddSingleton<ILuFieldsExpressions<DateTime, DateTime>, LuFieldsExpressions<DateTime, DateTime>>();
69
+//            services.AddSingleton<ILuFieldsExpressions<DateTimeOffset, DateTimeOffset>, LuFieldsExpressions<DateTimeOffset, DateTimeOffset>>();
70
+//            services.AddSingleton<ILuFieldsExpressions<DateTime, DateTimeOffset>, LuFieldsExpressions<DateTime, DateTimeOffset>>();
71
+//            services.AddSingleton<ILuFieldsExpressions<DateTimeOffset, DateTime>, LuFieldsExpressions<DateTimeOffset, DateTime>>();
72
+//
73
+//            services.AddSingleton<ILuFieldsExpressions<DateTime?, DateTime?>, LuFieldsExpressions<DateTime?, DateTime?>>();
74
+//            services.AddSingleton<ILuFieldsExpressions<DateTimeOffset?, DateTimeOffset?>, LuFieldsExpressions<DateTimeOffset?, DateTimeOffset?>>();
75
+//            services.AddSingleton<ILuFieldsExpressions<DateTime?, DateTimeOffset?>, LuFieldsExpressions<DateTime?, DateTimeOffset?>>();
76
+//            services.AddSingleton<ILuFieldsExpressions<DateTimeOffset?, DateTime?>, LuFieldsExpressions<DateTimeOffset?, DateTime?>>();
65 77
 
66 78
             services.AddDbContext<Luticate2DbContext>(options =>
67 79
             {

+ 191
- 0
Luticate2.Auth.Tests/Business/Fields/LuDboModelExpressionConverterTests.cs 查看文件

@@ -0,0 +1,191 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq.Expressions;
4
+using System.Reflection;
5
+using Luticate2.Auth.Business;
6
+using Luticate2.Auth.Business.Fields;
7
+using Luticate2.Auth.Business.Fields.DMEC;
8
+using Luticate2.Auth.Dbo;
9
+using Luticate2.Auth.Dbo.Result;
10
+using Luticate2.Auth.Interfaces;
11
+using Microsoft.Extensions.DependencyInjection;
12
+using Xunit;
13
+
14
+namespace Luticate2.Auth.Tests.Business.Fields
15
+{
16
+    public class TestDbo1
17
+    {
18
+        public Guid Id { get; set; }
19
+
20
+        public string Name { get; set; }
21
+
22
+        public IList<TestDbo2> TestDbo2s { get; set; }
23
+    }
24
+
25
+    public class TestDbo2
26
+    {
27
+        public Guid Id { get; set; }
28
+
29
+        public string Name { get; set; }
30
+
31
+        public TestDbo1 TestDbo1 { get; set; }
32
+    }
33
+
34
+    public class TestModel1
35
+    {
36
+        public Guid Id { get; set; }
37
+
38
+        public string Name { get; set; }
39
+
40
+        public ICollection<TestModel2> TestModel2 { get; set; }
41
+    }
42
+
43
+    public class TestModel2
44
+    {
45
+        public Guid Id { get; set; }
46
+
47
+        public string Name { get; set; }
48
+
49
+        public Guid TestModel1Id { get; set; }
50
+
51
+        public TestModel1 TestModel1 { get; set; }
52
+    }
53
+
54
+    public class LuDMECTest1 : LuExpressionConverter<TestDbo1, TestModel1>
55
+    {
56
+        public LuDMECTest1(IServiceProvider serviceProvider) : base(serviceProvider)
57
+        {
58
+        }
59
+
60
+        protected override LuResult<Expression> ConvertInternal(Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
61
+        {
62
+            var expression = expressions.Peek();
63
+            if (expression is MemberExpression memberExpression)
64
+            {
65
+                if (MemberMatch(x => x.Id, memberExpression))
66
+                {
67
+                    return MakeMemberAccess(x => x.Id, expressions, baseExpression, options);
68
+                }
69
+                if (MemberMatch(x => x.Name, memberExpression))
70
+                {
71
+                    return MakeMemberAccess(x => x.Name, expressions, baseExpression, options);
72
+                }
73
+                if (MemberMatch(x => x.TestDbo2s, memberExpression))
74
+                {
75
+                    return MakeMemberAccess(x => x.TestModel2, expressions, baseExpression, options);
76
+                }
77
+            }
78
+
79
+            return base.ConvertInternal(expressions, baseExpression, options);
80
+        }
81
+    }
82
+
83
+    public class LuDMECTest2 : LuExpressionConverter<TestDbo2, TestModel2>
84
+    {
85
+        public LuDMECTest2(IServiceProvider serviceProvider) : base(serviceProvider)
86
+        {
87
+        }
88
+
89
+        protected override LuResult<Expression> ConvertInternal(Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
90
+        {
91
+            var expression = expressions.Peek();
92
+            if (expression is MemberExpression memberExpression)
93
+            {
94
+                if (MemberMatch(x => x.Id, memberExpression))
95
+                {
96
+                    return MakeMemberAccess(x => x.Id, expressions, baseExpression, options);
97
+                }
98
+                if (MemberMatch(x => x.Name, memberExpression))
99
+                {
100
+                    return MakeMemberAccess(x => x.Name, expressions, baseExpression, options);
101
+                }
102
+                if (MemberMatch(x => x.TestDbo1, memberExpression))
103
+                {
104
+                    return MakeMemberAccess(x => x.TestModel1, expressions, baseExpression, options);
105
+                }
106
+            }
107
+
108
+            return base.ConvertInternal(expressions, baseExpression, options);
109
+        }
110
+    }
111
+
112
+    public class LuDboModelExpressionConverterTests
113
+    {
114
+        public IServiceProvider GetServiceProvider()
115
+        {
116
+            var services = new ServiceCollection();
117
+            services.AddSingleton<ILuExpressionConverter<TestDbo1, TestModel1>, LuDMECTest1>();
118
+            services.AddSingleton<ILuExpressionConverter<TestDbo2, TestModel2>, LuDMECTest2>();
119
+            services.AddSingleton<ILuExpressionConverter<string, string>, LuExpressionConverterIdentity<string>>();
120
+            services.AddSingleton<ILuExpressionConverter<Guid, Guid>, LuExpressionConverterIdentity<Guid>>();
121
+
122
+            var serviceProvider = services.BuildServiceProvider();
123
+            return serviceProvider;
124
+        }
125
+
126
+//        [Fact]
127
+//        public void Test0()
128
+//        {
129
+//            var serviceProvider = GetServiceProvider();
130
+//            var converter = serviceProvider.GetService<ILuDboModelExpressionConverter<TestDbo1, TestModel1>>();
131
+//            Expression<Func<TestDbo1, TestDbo1>> expDbo = (x => x);
132
+//            Expression<Func<TestModel1, object>> expModel = (x => (object) x);
133
+//            var convertResult = converter.ConvertLamdba(expDbo);
134
+//            Assert.Equal(LuStatus.Success.ToInt(), convertResult.Status);
135
+//            Assert.NotNull(convertResult.Data);
136
+//            Assert.Equal(expModel.ToString(), convertResult.Data.ToString());
137
+//        }
138
+//
139
+//        [Fact]
140
+//        public void Test1()
141
+//        {
142
+//            var serviceProvider = GetServiceProvider();
143
+//            var converter = serviceProvider.GetService<ILuDboModelExpressionConverter<TestDbo1, TestModel1>>();
144
+//            Expression<Func<TestDbo1, Guid>> expDbo = (x => x.Id);
145
+//            Expression<Func<TestModel1, object>> expModel = (x => (object) x.Id);
146
+//            var convertResult = converter.ConvertLamdba(expDbo);
147
+//            Assert.Equal(LuStatus.Success.ToInt(), convertResult.Status);
148
+//            Assert.NotNull(convertResult.Data);
149
+//            Assert.Equal(expModel.ToString(), convertResult.Data.ToString());
150
+//        }
151
+//
152
+//        [Fact]
153
+//        public void Test2()
154
+//        {
155
+//            var serviceProvider = GetServiceProvider();
156
+//            var converter = serviceProvider.GetService<ILuDboModelExpressionConverter<TestDbo2, TestModel2>>();
157
+//            Expression<Func<TestDbo2, Guid>> expDbo = (x => x.TestDbo1.Id);
158
+//            Expression<Func<TestModel2, object>> expModel = (x => (object) x.TestModel1.Id);
159
+//            var convertResult = converter.ConvertLamdba(expDbo);
160
+//            Assert.Equal(LuStatus.Success.ToInt(), convertResult.Status);
161
+//            Assert.NotNull(convertResult.Data);
162
+//            Assert.Equal(expModel.ToString(), convertResult.Data.ToString());
163
+//        }
164
+//
165
+//        [Fact]
166
+//        public void Test3()
167
+//        {
168
+//            var serviceProvider = GetServiceProvider();
169
+//            var converter = serviceProvider.GetService<ILuDboModelExpressionConverter<TestDbo2, TestModel2>>();
170
+//            Expression<Func<TestDbo2, int>> expDbo = (x => x.TestDbo1.Name.Length);
171
+//            Expression<Func<TestModel2, object>> expModel = (x => (object) x.TestModel1.Name.Length);
172
+//            var convertResult = converter.ConvertLamdba(expDbo);
173
+//            Assert.Equal(LuStatus.Success.ToInt(), convertResult.Status);
174
+//            Assert.NotNull(convertResult.Data);
175
+//            Assert.Equal(expModel.ToString(), convertResult.Data.ToString());
176
+//        }
177
+//
178
+//        [Fact]
179
+//        public void Test4()
180
+//        {
181
+//            var serviceProvider = GetServiceProvider();
182
+//            var converter = serviceProvider.GetService<ILuDboModelExpressionConverter<TestDbo2, TestModel2>>();
183
+//            Expression<Func<TestDbo2, bool>> expDbo = (x => x.TestDbo1.Name.Length == 0 || x.Name.Length != 0);
184
+//            Expression<Func<TestModel2, object>> expModel = (x => (object) (x.TestModel1.Name.Length == 0 || x.Name.Length != 0));
185
+//            var convertResult = converter.ConvertLamdba(expDbo);
186
+//            Assert.Equal(LuStatus.Success.ToInt(), convertResult.Status);
187
+//            Assert.NotNull(convertResult.Data);
188
+//            Assert.Equal(expModel.ToString(), convertResult.Data.ToString());
189
+//        }
190
+    }
191
+}

+ 0
- 135
Luticate2.Auth.Tests/Business/FieldsExpressions/LuFieldsExpressionsTests.cs 查看文件

@@ -1,135 +0,0 @@
1
-using System;
2
-using System.Linq.Expressions;
3
-using Luticate2.Auth.Business;
4
-using Luticate2.Auth.Business.Fields;
5
-using Luticate2.Auth.Business.FieldsExpressions;
6
-using Luticate2.Auth.Business.FieldsExpressions.Basic;
7
-using Luticate2.Auth.Dbo;
8
-using Luticate2.Auth.Dbo.Fields;
9
-using Luticate2.Auth.Dbo.Result;
10
-using Luticate2.Auth.Interfaces;
11
-using Microsoft.Extensions.DependencyInjection;
12
-using Xunit;
13
-
14
-namespace Luticate2.Auth.Tests.Business.FieldsExpressions
15
-{
16
-    public class LuFieldsExpressionsTestDbo1TestModel1 : LuFieldsExpressions<TestDbo1, TestModel1>
17
-    {
18
-        public LuFieldsExpressionsTestDbo1TestModel1(IServiceProvider serviceProvider) : base(serviceProvider)
19
-        {
20
-        }
21
-
22
-        protected override LuResult<Expression<Func<TType1, object>>> GetExpressionInternal<TType1>(Expression<Func<TType1, TestModel1>> modelProperty, LuFieldDbo field)
23
-        {
24
-            if (field.StartsWith<TestDbo1>(x => x.MyInt))
25
-            {
26
-                return GetSubField<TType1, int, int>(modelProperty, field, x => x.MyInt);
27
-            }
28
-            else if (field.StartsWith<TestDbo1>(x => x.Metadata))
29
-            {
30
-                return GetSubField<TType1, MetadataDbo, MetadataModel>(modelProperty, field, x => x.MetadataModel);
31
-            }
32
-
33
-            return base.GetExpressionInternal(modelProperty, field);
34
-        }
35
-    }
36
-
37
-    public class LuFieldsExpressionsMetadataDboMetadataModel : LuFieldsExpressions<MetadataDbo, MetadataModel>
38
-    {
39
-        public LuFieldsExpressionsMetadataDboMetadataModel(IServiceProvider serviceProvider) : base(serviceProvider)
40
-        {
41
-        }
42
-
43
-        protected override LuResult<Expression<Func<TType1, object>>> GetExpressionInternal<TType1>(Expression<Func<TType1, MetadataModel>> modelProperty, LuFieldDbo field)
44
-        {
45
-            if (field.StartsWith<MetadataDbo>(x => x.Id))
46
-            {
47
-                return GetSubField<TType1, Guid, Guid>(modelProperty, field, x => x.Id);
48
-            }
49
-
50
-            return base.GetExpressionInternal(modelProperty, field);
51
-        }
52
-    }
53
-    
54
-    public class TestDbo1
55
-    {
56
-        public string MyString { get; set; }
57
-
58
-        public int MyInt { get; set; }
59
-
60
-        public MetadataDbo Metadata { get; set; }
61
-    }
62
-
63
-    public class MetadataDbo
64
-    {
65
-        public Guid Id { get; set; }
66
-
67
-        public DateTime CreatedAt { get; set; }
68
-    }
69
-    
70
-    public class TestModel1
71
-    {
72
-        public string MyString { get; set; }
73
-
74
-        public int MyInt { get; set; }
75
-
76
-        public MetadataModel MetadataModel { get; set; }
77
-    }
78
-
79
-    public class MetadataModel
80
-    {
81
-        public Guid Id { get; set; }
82
-
83
-        public DateTime CreatedAt { get; set; }
84
-    }
85
-    
86
-    public class LuFieldsExpressionsTests
87
-    {
88
-        public IServiceProvider GetServiceProvider()
89
-        {
90
-            var serviceCollection = new ServiceCollection();
91
-
92
-            serviceCollection.AddSingleton<ILuFieldsExpressions<TestDbo1, TestModel1>, LuFieldsExpressionsTestDbo1TestModel1>();
93
-            serviceCollection.AddSingleton<ILuFieldsExpressions<MetadataDbo, MetadataModel>, LuFieldsExpressionsMetadataDboMetadataModel>();
94
-            serviceCollection.AddSingleton<ILuFieldsExpressions<string, string>, LuFieldsExpressionsString>();
95
-            serviceCollection.AddSingleton<ILuFieldsExpressions<int, int>, LuFieldsExpressions<int, int>>();
96
-            serviceCollection.AddSingleton<ILuFieldsExpressions<Guid, Guid>, LuFieldsExpressions<Guid, Guid>>();
97
-
98
-            var serviceProvider = serviceCollection.BuildServiceProvider();
99
-            return serviceProvider;
100
-        }
101
-        
102
-        [Fact]
103
-        public void Test1()
104
-        {
105
-            var serviceProvider = GetServiceProvider();
106
-            var fieldExpression = serviceProvider.GetService<ILuFieldsExpressions<TestDbo1, TestModel1>>();
107
-            var exprResult = fieldExpression.GetExpression<TestModel1>(x => x, LuFieldDbo.Make("Metadata.Id"));
108
-            Assert.Equal(LuStatus.Success.ToInt(), exprResult.Status);
109
-            Assert.NotNull(exprResult.Data);
110
-            var operand = LuExpressionUtils.GetFromConvert(exprResult.Data);
111
-            var str = operand.ToString();
112
-            Assert.Equal("x.MetadataModel.Id", str);
113
-        }
114
-
115
-        [Fact]
116
-        public void TestError1()
117
-        {
118
-            var serviceProvider = GetServiceProvider();
119
-            var fieldExpression = serviceProvider.GetService<ILuFieldsExpressions<TestDbo1, TestModel1>>();
120
-            var exprResult = fieldExpression.GetExpression<TestModel1>(x => x, LuFieldDbo.Make("Metadata.Id.NxField"));
121
-            Assert.Equal(LuStatus.InputError.ToInt(), exprResult.Status);
122
-            Assert.Null(exprResult.Data);
123
-        }
124
-
125
-        [Fact]
126
-        public void TestError2()
127
-        {
128
-            var serviceProvider = GetServiceProvider();
129
-            var fieldExpression = serviceProvider.GetService<ILuFieldsExpressions<TestDbo1, TestModel1>>();
130
-            var exprResult = fieldExpression.GetExpression<TestModel1>(x => x, LuFieldDbo.Make("Metadata.*"));
131
-            Assert.Equal(LuStatus.InputError.ToInt(), exprResult.Status);
132
-            Assert.Null(exprResult.Data);
133
-        }
134
-    }
135
-}

+ 155
- 22
Luticate2.Auth.Tests/RandomTests.cs 查看文件

@@ -1,41 +1,174 @@
1
-using System.Linq;
2
-using Luticate2.Auth.DataAccess;
3
-using Luticate2.Auth.DataAccess.Models;
4
-using Microsoft.EntityFrameworkCore;
1
+using System;
2
+using System.Linq;
3
+using System.Linq.Expressions;
4
+using Luticate2.Auth.Business.Fields;
5
+using Luticate2.Auth.Business.Fields.DMEC;
6
+using Luticate2.Auth.Interfaces;
7
+using Luticate2.Auth.Tests.Business.Fields;
8
+using Microsoft.Extensions.DependencyInjection;
9
+using Microsoft.Extensions.DependencyInjection.Extensions;
5 10
 using Xunit;
6 11
 
7 12
 namespace Luticate2.Auth.Tests
8 13
 {
9 14
     public class RandomTests
10 15
     {
16
+
17
+//        [Fact]
18
+//        public void Test1()
19
+//        {
20
+//            var dbContext = new luticate2Context();
21
+//            var items = dbContext.LuGroups.Where(groups => groups.LuGroupsObjects.Any(x => x.Priority == 0));
22
+//            var list = items.ToList();
23
+//            Assert.NotNull(list);
24
+//            Assert.Equal(1, list.Count);
25
+//        }
26
+//
27
+//        [Fact]
28
+//        public void Test2()
29
+//        {
30
+//            var dbContext = new luticate2Context();
31
+//            var items = dbContext.LuGroups.OrderBy(x => x.Id).Where(groups => groups.LuGroupsObjects.Any(x => x.Priority == 0));
32
+//            var list = items.ToList();
33
+//            Assert.NotNull(list);
34
+//            Assert.Equal(1, list.Count);
35
+//        }
36
+//
37
+//        [Fact]
38
+//        public void Test3()
39
+//        {
40
+//            var dbContext = new luticate2Context();
41
+//            var items = dbContext.LuGroups.OrderBy(x => x.Id);
42
+//            var list = items.ToList();
43
+//            Assert.NotNull(list);
44
+//            Assert.Equal(2, list.Count);
45
+//        }
46
+
47
+        protected void AddILuExpressionConverter<TTypeFrom, TTypeTo, TTypeImpl>(IServiceCollection services)
48
+            where TTypeImpl : class, ILuExpressionConverter<TTypeFrom, TTypeTo>
49
+        {
50
+            services.AddSingleton<ILuExpressionConverter<TTypeFrom, TTypeTo>, TTypeImpl>();
51
+            services.TryAddSingleton<ILuExpressionConverter<TTypeFrom>, TTypeImpl>();
52
+        }
53
+
54
+        protected IServiceProvider GetServiceProvider()
55
+        {
56
+            var services = new ServiceCollection();
57
+            services.AddSingleton<LuExpressionConverterEnumerable>();
58
+            AddILuExpressionConverter<TestDbo1, TestModel1, LuDMECTest1>(services);
59
+            AddILuExpressionConverter<TestDbo2, TestModel2, LuDMECTest2>(services);
60
+            AddILuExpressionConverter<LuExpressionConverterStaticMethods, LuExpressionConverterStaticMethods, LuExpressionConverterStaticMethods>(services);
61
+            AddILuExpressionConverter<string, string, LuExpressionConverterIdentity<string>>(services);
62
+            AddILuExpressionConverter<Guid, Guid, LuExpressionConverterIdentity<Guid>>(services);
63
+            AddILuExpressionConverter<bool, bool, LuExpressionConverterIdentity<bool>>(services);
64
+
65
+            var serviceProvider = services.BuildServiceProvider();
66
+            return serviceProvider;
67
+        }
68
+
69
+        [Fact]
70
+        public void Test4()
71
+        {
72
+            Expression<Func<TestDbo2, Guid>> expDbo = (x => x.TestDbo1.Id);
73
+            Expression<Func<TestModel2, Guid>> expModel = (x => x.TestModel1.Id);
74
+            var options = new LuExpressionConverterOptions
75
+            {
76
+                Parameter = Expression.Parameter(typeof(TestModel2), "x")
77
+            };
78
+            var converter = new LuExpressionConverterVisitor(options, GetServiceProvider());
79
+            var result = converter.Visit(expDbo.Body);
80
+            var lamdba = result != null ? Expression.Lambda<Func<TestModel2, Guid>>(result, options.Parameter) : null;
81
+            Assert.Equal(expModel.ToString(), lamdba?.ToString());
82
+        }
83
+
84
+        [Fact]
85
+        public void Test5()
86
+        {
87
+            Expression<Func<TestDbo2, int>> expDbo = (x => 0);
88
+            Expression<Func<TestModel2, int>> expModel = (x => 0);
89
+            var options = new LuExpressionConverterOptions
90
+            {
91
+                Parameter = Expression.Parameter(typeof(TestModel2), "x")
92
+            };
93
+            var converter = new LuExpressionConverterVisitor(options, GetServiceProvider());
94
+            var result = converter.Visit(expDbo.Body);
95
+            var lamdba = result != null ? Expression.Lambda<Func<TestModel2, int>>(result, options.Parameter) : null;
96
+            Assert.Equal(expModel.ToString(), lamdba?.ToString());
97
+        }
98
+
99
+        [Fact]
100
+        public void Test6()
101
+        {
102
+            Expression<Func<TestDbo2, bool>> expDbo = (x => x.Name.Contains("s"));
103
+            Expression<Func<TestModel2, bool>> expModel = (x => x.Name.Contains("s"));
104
+            var options = new LuExpressionConverterOptions
105
+            {
106
+                Parameter = Expression.Parameter(typeof(TestModel2), "x")
107
+            };
108
+            var converter = new LuExpressionConverterVisitor(options, GetServiceProvider());
109
+            var result = converter.Visit(expDbo.Body);
110
+            var lamdba = result != null ? Expression.Lambda<Func<TestModel2, bool>>(result, options.Parameter) : null;
111
+            Assert.Equal(expModel.ToString(), lamdba?.ToString());
112
+        }
113
+
114
+        [Fact]
115
+        public void Test7()
116
+        {
117
+            Expression<Func<TestDbo2, bool>> expDbo = (x => x.TestDbo1.Name.Contains("s"));
118
+            Expression<Func<TestModel2, bool>> expModel = (x => x.TestModel1.Name.Contains("s"));
119
+            var options = new LuExpressionConverterOptions
120
+            {
121
+                Parameter = Expression.Parameter(typeof(TestModel2), "x")
122
+            };
123
+            var converter = new LuExpressionConverterVisitor(options, GetServiceProvider());
124
+            var result = converter.Visit(expDbo.Body);
125
+            var lamdba = result != null ? Expression.Lambda<Func<TestModel2, bool>>(result, options.Parameter) : null;
126
+            Assert.Equal(expModel.ToString(), lamdba?.ToString());
127
+        }
128
+
11 129
         [Fact]
12
-        public void Test1()
130
+        public void Test8()
13 131
         {
14
-            var dbContext = new luticate2Context();
15
-            var items = dbContext.LuGroups.Where(groups => groups.LuGroupsObjects.Any(x => x.Priority == 0));
16
-            var list = items.ToList();
17
-            Assert.NotNull(list);
18
-            Assert.Equal(1, list.Count);
132
+            Expression<Func<TestDbo2, bool>> expDbo = (x => x.TestDbo1.Name.Contains(x.Name));
133
+            Expression<Func<TestModel2, bool>> expModel = (x => x.TestModel1.Name.Contains(x.Name));
134
+            var options = new LuExpressionConverterOptions
135
+            {
136
+                Parameter = Expression.Parameter(typeof(TestModel2), "x")
137
+            };
138
+            var converter = new LuExpressionConverterVisitor(options, GetServiceProvider());
139
+            var result = converter.Visit(expDbo.Body);
140
+            var lamdba = result != null ? Expression.Lambda<Func<TestModel2, bool>>(result, options.Parameter) : null;
141
+            Assert.Equal(expModel.ToString(), lamdba?.ToString());
19 142
         }
20 143
 
21 144
         [Fact]
22
-        public void Test2()
145
+        public void Test9()
23 146
         {
24
-            var dbContext = new luticate2Context();
25
-            var items = dbContext.LuGroups.OrderBy(x => x.Id).Where(groups => groups.LuGroupsObjects.Any(x => x.Priority == 0));
26
-            var list = items.ToList();
27
-            Assert.NotNull(list);
28
-            Assert.Equal(1, list.Count);
147
+            Expression<Func<TestDbo1, bool>> expDbo = (x => x.TestDbo2s.Any());
148
+            Expression<Func<TestModel1, bool>> expModel = (x => x.TestModel2.Any());
149
+            var options = new LuExpressionConverterOptions
150
+            {
151
+                Parameter = Expression.Parameter(typeof(TestModel1), "x")
152
+            };
153
+            var converter = new LuExpressionConverterVisitor(options, GetServiceProvider());
154
+            var result = converter.Visit(expDbo.Body);
155
+            var lamdba = result != null ? Expression.Lambda<Func<TestModel2, bool>>(result, options.Parameter) : null;
156
+            Assert.Equal(expModel.ToString(), lamdba?.ToString());
29 157
         }
30 158
 
31 159
         [Fact]
32
-        public void Test3()
160
+        public void Test10()
33 161
         {
34
-            var dbContext = new luticate2Context();
35
-            var items = dbContext.LuGroups.OrderBy(x => x.Id);
36
-            var list = items.ToList();
37
-            Assert.NotNull(list);
38
-            Assert.Equal(2, list.Count);
162
+            Expression<Func<TestDbo1, bool>> expDbo = (x => x.TestDbo2s.Any(y => y.Name.Contains(x.Name + "s")));
163
+            Expression<Func<TestModel1, bool>> expModel = (x => x.TestModel2.Any(y => y.Name.Contains(x.Name + "s")));
164
+            var options = new LuExpressionConverterOptions
165
+            {
166
+                Parameter = Expression.Parameter(typeof(TestModel1), "x")
167
+            };
168
+            var converter = new LuExpressionConverterVisitor(options, GetServiceProvider());
169
+            var result = converter.Visit(expDbo.Body);
170
+            var lamdba = result != null ? Expression.Lambda<Func<TestModel2, bool>>(result, options.Parameter) : null;
171
+            Assert.Equal(expModel.ToString(), lamdba?.ToString());
39 172
         }
40 173
     }
41 174
 }

+ 36
- 0
Luticate2.Auth/Business/Auth/DMEC/LuDMECGroupsToModel.cs 查看文件

@@ -0,0 +1,36 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq.Expressions;
4
+using Luticate2.Auth.Business.Fields;
5
+using Luticate2.Auth.Business.Fields.DMEC;
6
+using Luticate2.Auth.DataAccess.Models;
7
+using Luticate2.Auth.Dbo.Auth;
8
+using Luticate2.Auth.Dbo.Result;
9
+
10
+namespace Luticate2.Auth.Business.Auth.DMEC
11
+{
12
+    public class LuDMECGroupsToModel : LuExpressionConverter<LuGroupDbo, LuGroups>
13
+    {
14
+        public LuDMECGroupsToModel(IServiceProvider serviceProvider) : base(serviceProvider)
15
+        {
16
+        }
17
+
18
+        protected override LuResult<Expression> ConvertInternal(Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
19
+        {
20
+            var expression = expressions.Peek();
21
+            if (expression is MemberExpression memberExpression)
22
+            {
23
+                if (MemberMatch(x => x.Id, memberExpression))
24
+                {
25
+                    return MakeMemberAccess(x => x.Id, expressions, baseExpression, options);
26
+                }
27
+                if (MemberMatch(x => x.Name, memberExpression))
28
+                {
29
+                    return MakeMemberAccess(x => x.Name, expressions, baseExpression, options);
30
+                }
31
+            }
32
+
33
+            return base.ConvertInternal(expressions, baseExpression, options);
34
+        }
35
+    }
36
+}

+ 0
- 37
Luticate2.Auth/Business/Auth/FieldsExpressions/LuFieldsExpressionsLuGroupDboLuGroups.cs 查看文件

@@ -1,37 +0,0 @@
1
-using System;
2
-using System.Linq.Expressions;
3
-using Luticate2.Auth.Business.Fields;
4
-using Luticate2.Auth.Business.FieldsExpressions;
5
-using Luticate2.Auth.DataAccess.Models;
6
-using Luticate2.Auth.Dbo.Auth;
7
-using Luticate2.Auth.Dbo.Fields;
8
-using Luticate2.Auth.Dbo.Result;
9
-
10
-namespace Luticate2.Auth.Business.Auth.FieldsExpressions
11
-{
12
-    public class LuFieldsExpressionsLuGroupDboLuGroups : LuFieldsExpressions<LuGroupDbo, LuGroups>
13
-    {
14
-        public LuFieldsExpressionsLuGroupDboLuGroups(IServiceProvider serviceProvider) : base(serviceProvider)
15
-        {
16
-        }
17
-
18
-        protected override LuResult<Expression<Func<TType1, object>>> GetExpressionInternal<TType1>(
19
-            Expression<Func<TType1, LuGroups>> modelProperty, LuFieldDbo field)
20
-        {
21
-            if (field.StartsWith<LuGroupDbo>(x => x.Id))
22
-            {
23
-                return GetSubField<TType1, Guid, Guid>(modelProperty, field, x => x.Id);
24
-            }
25
-            else if (field.StartsWith<LuGroupDbo>(x => x.Name))
26
-            {
27
-                return GetSubField<TType1, string, string>(modelProperty, field, x => x.Name);
28
-            }
29
-            else if (field.StartsWith<LuGroupDbo>(x => x.Metadata))
30
-            {
31
-                return GetSubField<TType1, LuObjectsMetadataDbo, LuObjectsMetadata>(modelProperty, field, x => x.IdNavigation);
32
-            }
33
-
34
-            return base.GetExpressionInternal(modelProperty, field);
35
-        }
36
-    }
37
-}

+ 0
- 36
Luticate2.Auth/Business/Auth/FieldsExpressions/LuFieldsExpressionsLuMetadataDboLuMetadata.cs 查看文件

@@ -1,36 +0,0 @@
1
-using System;
2
-using System.Linq.Expressions;
3
-using Luticate2.Auth.Business.Fields;
4
-using Luticate2.Auth.Business.FieldsExpressions;
5
-using Luticate2.Auth.DataAccess.Models;
6
-using Luticate2.Auth.Dbo.Auth;
7
-using Luticate2.Auth.Dbo.Fields;
8
-using Luticate2.Auth.Dbo.Result;
9
-
10
-namespace Luticate2.Auth.Business.Auth.FieldsExpressions
11
-{
12
-    public class LuFieldsExpressionsLuMetadataDboLuMetadata : LuFieldsExpressions<LuObjectsMetadataDbo, LuObjectsMetadata>
13
-    {
14
-        public LuFieldsExpressionsLuMetadataDboLuMetadata(IServiceProvider serviceProvider) : base(serviceProvider)
15
-        {
16
-        }
17
-
18
-        protected override LuResult<Expression<Func<TType1, object>>> GetExpressionInternal<TType1>(Expression<Func<TType1, LuObjectsMetadata>> modelProperty, LuFieldDbo field)
19
-        {
20
-            if (field.StartsWith<LuObjectsMetadataDbo>(x => x.Id))
21
-            {
22
-                return GetSubField<TType1, Guid, Guid>(modelProperty, field, x => x.Id);
23
-            }
24
-            if (field.StartsWith<LuObjectsMetadataDbo>(x => x.CreatedAt))
25
-            {
26
-                return GetSubField<TType1, DateTime, DateTimeOffset>(modelProperty, field, x => x.CreatedAt);
27
-            }
28
-            if (field.StartsWith<LuObjectsMetadataDbo>(x => x.UpdatedAt))
29
-            {
30
-                return GetSubField<TType1, DateTime?, DateTimeOffset?>(modelProperty, field, x => x.UpdatedAt);
31
-            }
32
-
33
-            return base.GetExpressionInternal(modelProperty, field);
34
-        }
35
-    }
36
-}

+ 46
- 46
Luticate2.Auth/Business/Crud/LuEfCrudBusiness.cs 查看文件

@@ -2,6 +2,8 @@
2 2
 using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Linq.Expressions;
5
+using Luticate2.Auth.Business.Fields;
6
+using Luticate2.Auth.Business.Fields.DMEC;
5 7
 using Luticate2.Auth.Dbo;
6 8
 using Luticate2.Auth.Dbo.Fields;
7 9
 using Luticate2.Auth.Dbo.Pagination;
@@ -75,58 +77,56 @@ namespace Luticate2.Auth.Business.Crud
75 77
 
76 78
         protected virtual LuResult<IQueryable<TModel>> Filter(LuFilterDbo filter, IQueryable<TModel> queryable)
77 79
         {
78
-            return LuResult<IQueryable<TModel>>.Ok(queryable.Where((Expression<Func<TModel, bool>>) filter.Expression));
79
-        }
80
+            var lamdbaDbo = (Expression<Func<TDbo, bool>>) filter.Expression;
80 81
 
81
-        protected IQueryable<TModel> ConvertAndOrderByQueryable<T>(Expression<Func<TModel, object>> exp,
82
-            LuOrderByFieldDbo orderByfield, IQueryable<TModel> queryable, Expression expressionNoConvert)
83
-        {
84
-            var ordered = queryable as IOrderedQueryable<TModel>;
85
-            var expType = expressionNoConvert.Type;
86
-            var type = typeof(T);
87
-            if (type.IsAssignableFrom(expType))
82
+            var options = new LuExpressionConverterOptions
88 83
             {
89
-                var expLambda = Expression.Lambda<Func<TModel, T>>(expressionNoConvert, exp.Parameters);
90
-                if (ordered != null)
91
-                {
92
-                    ordered = orderByfield.Asc ? ordered.ThenBy(expLambda) : ordered.ThenByDescending(expLambda);
93
-                }
94
-                else
95
-                {
96
-                    ordered = orderByfield.Asc ? queryable.OrderBy(expLambda) : queryable.OrderByDescending(expLambda);
97
-                }
98
-            }
99
-
100
-            return ordered ?? queryable;
84
+                Parameter = Expression.Parameter(typeof(TModel), "x")
85
+            };
86
+            var converter = new LuExpressionConverterVisitor(options, ServiceProvider);
87
+            var result = converter.Visit(lamdbaDbo.Body);
88
+            var lamdbaModel = result != null ? Expression.Lambda<Func<TModel, bool>>(result, options.Parameter) : null;
89
+            return LuResult<IQueryable<TModel>>.Ok(queryable.Where(lamdbaModel));
90
+
91
+//            var converter = ServiceProvider.GetService<ILuExpressionConverter<TDbo, TModel>>();
92
+//            if (converter == null)
93
+//            {
94
+//                return LuResult<IQueryable<TModel>>.Error(LuStatus.InternalError.ToInt(), $"Could not get service: ILuDboModelExpressionConverter<{typeof(TModel).Name}, {typeof(TDbo).Name}>");
95
+//            }
96
+//
97
+//            var lamdba = (Expression<Func<TDbo, bool>>) filter.Expression;
98
+//            var options = new LuDMECOptions
99
+//            {
100
+//                Parameter = Expression.Parameter(typeof(TModel), lamdba.Parameters[0].Name)
101
+//            };
102
+//            var convertResult = converter.ConvertExpression(lamdba.Body, options);
103
+//            if (!convertResult)
104
+//            {
105
+//                return convertResult.To<IQueryable<TModel>>();
106
+//            }
107
+//
108
+//            var lambdaNoConvert = Expression.Lambda<Func<TModel, bool>>(convertResult.Data, options.Parameter);
109
+//
110
+//            return LuResult<IQueryable<TModel>>.Ok(queryable.Where(lambdaNoConvert));
111
+            return LuResult<IQueryable<TModel>>.Ok(queryable);
101 112
         }
102 113
 
103 114
         protected virtual LuResult<IQueryable<TModel>> OrderByField(LuOrderByFieldDbo orderByfield, IQueryable<TModel> queryable)
104 115
         {
105
-            var expressionBuilder = ServiceProvider.GetService<ILuFieldsExpressions<TDbo, TModel>>();
106
-            var expressionResult = expressionBuilder.GetExpression<TModel>(x => x, orderByfield.Field);
107
-            if (!expressionResult)
108
-            {
109
-                return expressionResult.To<IQueryable<TModel>>();
110
-            }
111
-
112
-            var expression = expressionResult.Data;
113
-            var expressionNoConvert = LuExpressionUtils.GetFromConvert(expression);
114
-
115
-            var ordered = ConvertAndOrderByQueryable<bool>(expression, orderByfield, queryable, expressionNoConvert);
116
-            ordered = ConvertAndOrderByQueryable<byte>(expression, orderByfield, ordered, expressionNoConvert);
117
-            ordered = ConvertAndOrderByQueryable<DateTime>(expression, orderByfield, ordered, expressionNoConvert);
118
-            ordered = ConvertAndOrderByQueryable<DateTimeOffset>(expression, orderByfield, ordered, expressionNoConvert);
119
-            ordered = ConvertAndOrderByQueryable<decimal>(expression, orderByfield, ordered, expressionNoConvert);
120
-            ordered = ConvertAndOrderByQueryable<double>(expression, orderByfield, ordered, expressionNoConvert);
121
-            ordered = ConvertAndOrderByQueryable<float>(expression, orderByfield, ordered, expressionNoConvert);
122
-            ordered = ConvertAndOrderByQueryable<Guid>(expression, orderByfield, ordered, expressionNoConvert);
123
-            ordered = ConvertAndOrderByQueryable<short>(expression, orderByfield, ordered, expressionNoConvert);
124
-            ordered = ConvertAndOrderByQueryable<int>(expression, orderByfield, ordered, expressionNoConvert);
125
-            ordered = ConvertAndOrderByQueryable<long>(expression, orderByfield, ordered, expressionNoConvert);
126
-            ordered = ConvertAndOrderByQueryable<char>(expression, orderByfield, ordered, expressionNoConvert);
127
-            ordered = ConvertAndOrderByQueryable<string>(expression, orderByfield, ordered, expressionNoConvert);
128
-            
129
-            return LuResult<IQueryable<TModel>>.Ok(ordered);
116
+//            var expressionBuilder = ServiceProvider.GetService<ILuDboModelExpressionConverter<TDbo, TModel>>();
117
+//            var expressionResult = expressionBuilder.ConvertLamdba<TModel>(orderByfield.);
118
+//            if (!expressionResult)
119
+//            {
120
+//                return expressionResult.To<IQueryable<TModel>>();
121
+//            }
122
+//
123
+//            var expression = expressionResult.Data;
124
+//            var expressionNoConvert = LuExpressionUtils.GetFromConvert(expression);
125
+//
126
+//            var ordered = queryable.OrderBy(expressionNoConvert);
127
+//
128
+//            return LuResult<IQueryable<TModel>>.Ok(ordered);
129
+            return LuResult<IQueryable<TModel>>.Ok(queryable);
130 130
         }
131 131
 
132 132
         protected virtual LuResult<IQueryable<TModel>> OrderBy(LuOrderByDbo orderBy, IQueryable<TModel> queryable)

+ 58
- 0
Luticate2.Auth/Business/Fields/DMEC/LuExpressionConverterEnumerable.cs 查看文件

@@ -0,0 +1,58 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Linq.Expressions;
5
+using Luticate2.Auth.Dbo;
6
+using Luticate2.Auth.Dbo.Result;
7
+using Luticate2.Auth.Interfaces;
8
+
9
+namespace Luticate2.Auth.Business.Fields.DMEC
10
+{
11
+    public class LuExpressionConverterEnumerable : ILuExpressionConverter
12
+    {
13
+        public IServiceProvider ServiceProvider { get; }
14
+
15
+        public LuExpressionConverterEnumerable(IServiceProvider serviceProvider)
16
+        {
17
+            ServiceProvider = serviceProvider;
18
+        }
19
+
20
+        protected LuResult<Expression> ConvertOther(Type typeFrom, Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
21
+        {
22
+            var type = typeof(ILuExpressionConverter<>);
23
+            var gtype = type.MakeGenericType(typeFrom);
24
+            var converter = (ILuExpressionConverter) ServiceProvider.GetService(gtype);
25
+            if (converter == null)
26
+            {
27
+                return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(), $"Could not get service: {gtype}>");
28
+            }
29
+
30
+            return converter.ConvertExpression(expressions, baseExpression, options);
31
+        }
32
+
33
+        public LuResult<Expression> ConvertExpression(Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
34
+        {
35
+            if (!expressions.Any())
36
+            {
37
+                return LuResult<Expression>.Ok(baseExpression);
38
+            }
39
+
40
+            var expression = expressions.Pop();
41
+            if (expression is MethodCallExpression methodCallExpression)
42
+            {
43
+                var argumentsModel = new List<Expression>();
44
+                foreach (var argumentDbo in methodCallExpression.Arguments)
45
+                {
46
+                    var converter = new LuExpressionConverterVisitor(options, ServiceProvider);
47
+                    var result = converter.Visit(argumentDbo);
48
+                    argumentsModel.Add(result);
49
+                }
50
+
51
+                var newExpression = Expression.Call(baseExpression, methodCallExpression.Method, argumentsModel);
52
+                return ConvertOther(newExpression.Type, expressions, newExpression, options);
53
+            }
54
+
55
+            return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(), "Not supported expression");
56
+        }
57
+    }
58
+}

+ 38
- 0
Luticate2.Auth/Business/Fields/DMEC/LuExpressionConverterIdentity.cs 查看文件

@@ -0,0 +1,38 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq.Expressions;
4
+using Luticate2.Auth.Dbo.Result;
5
+
6
+namespace Luticate2.Auth.Business.Fields.DMEC
7
+{
8
+    public class LuExpressionConverterIdentity<TType> : LuExpressionConverter<TType, TType>
9
+    {
10
+        public LuExpressionConverterIdentity(IServiceProvider serviceProvider) : base(serviceProvider)
11
+        {
12
+        }
13
+
14
+        protected override LuResult<Expression> ConvertInternal(Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
15
+        {
16
+            var expression = expressions.Pop();
17
+            if (expression is MemberExpression memberExpression)
18
+            {
19
+                var newExpression = Expression.MakeMemberAccess(baseExpression, memberExpression.Member);
20
+                return ConvertOther(newExpression.Type, expressions, newExpression, options);
21
+            }
22
+            else if (expression is MethodCallExpression methodCallExpression)
23
+            {
24
+                var argumentsModel = new List<Expression>();
25
+                foreach (var argumentDbo in methodCallExpression.Arguments)
26
+                {
27
+                    var converter = new LuExpressionConverterVisitor(options, ServiceProvider);
28
+                    var result = converter.Visit(argumentDbo);
29
+                    argumentsModel.Add(result);
30
+                }
31
+
32
+                var newExpression = Expression.Call(baseExpression, methodCallExpression.Method, argumentsModel);
33
+                return ConvertOther(newExpression.Type, expressions, newExpression, options);
34
+            }
35
+            return base.ConvertInternal(expressions, baseExpression, options);
36
+        }
37
+    }
38
+}

+ 9
- 0
Luticate2.Auth/Business/Fields/DMEC/LuExpressionConverterOptions.cs 查看文件

@@ -0,0 +1,9 @@
1
+using System.Linq.Expressions;
2
+
3
+namespace Luticate2.Auth.Business.Fields.DMEC
4
+{
5
+    public class LuExpressionConverterOptions
6
+    {
7
+        public ParameterExpression Parameter { get; set; }
8
+    }
9
+}

+ 35
- 0
Luticate2.Auth/Business/Fields/DMEC/LuExpressionConverterStaticMethods.cs 查看文件

@@ -0,0 +1,35 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Linq.Expressions;
5
+using Luticate2.Auth.Dbo.Result;
6
+using Luticate2.Auth.Interfaces;
7
+
8
+namespace Luticate2.Auth.Business.Fields.DMEC
9
+{
10
+    public class LuExpressionConverterStaticMethods : LuExpressionConverter<LuExpressionConverterStaticMethods, LuExpressionConverterStaticMethods>
11
+    {
12
+        public IDictionary<Type, Type> Converters { get; } = new Dictionary<Type, Type>();
13
+
14
+        public LuExpressionConverterStaticMethods(IServiceProvider serviceProvider) : base(serviceProvider)
15
+        {
16
+            Converters.Add(typeof(Enumerable), typeof(LuExpressionConverterEnumerable));
17
+        }
18
+
19
+        protected override LuResult<Expression> ConvertInternal(Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
20
+        {
21
+            var expression = expressions.Peek();
22
+            if (expression is MethodCallExpression methodCallExpression)
23
+            {
24
+                if (Converters.ContainsKey(methodCallExpression.Method.DeclaringType))
25
+                {
26
+                    var type = Converters[methodCallExpression.Method.DeclaringType];
27
+                    var service = (ILuExpressionConverter) ServiceProvider.GetService(type);
28
+                    return service.ConvertExpression(expressions, baseExpression, options);
29
+                }
30
+            }
31
+
32
+            return base.ConvertInternal(expressions, baseExpression, options);
33
+        }
34
+    }
35
+}

+ 96
- 0
Luticate2.Auth/Business/Fields/LuExpressionConverter.cs 查看文件

@@ -0,0 +1,96 @@
1
+using System;
2
+using System.Collections;
3
+using System.Collections.Generic;
4
+using System.Linq.Expressions;
5
+using Luticate2.Auth.Business.Fields.DMEC;
6
+using Luticate2.Auth.Dbo;
7
+using Luticate2.Auth.Dbo.Result;
8
+using Luticate2.Auth.Interfaces;
9
+using Microsoft.EntityFrameworkCore.Internal;
10
+
11
+namespace Luticate2.Auth.Business.Fields
12
+{
13
+    public class LuExpressionConverter<TTypeFrom, TTypeTo> : ILuExpressionConverter<TTypeFrom, TTypeTo>
14
+    {
15
+        protected IServiceProvider ServiceProvider { get; }
16
+
17
+        public LuExpressionConverter(IServiceProvider serviceProvider)
18
+        {
19
+            ServiceProvider = serviceProvider;
20
+        }
21
+
22
+        public virtual LuResult<Expression> ConvertExpression(Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
23
+        {
24
+            if (!expressions.Any())
25
+            {
26
+                return LuResult<Expression>.Ok(baseExpression);
27
+            }
28
+
29
+            var expression = expressions.Peek();
30
+            if (expression is ParameterExpression parameterExpression)
31
+            {
32
+                if (parameterExpression.Type != typeof(TTypeFrom))
33
+                {
34
+                    return LuResult<Expression>.Error(LuStatus.InputError.ToInt(), "Bad parameter expression type");
35
+                }
36
+
37
+                expressions.Pop();
38
+                return ConvertExpression(expressions, options.Parameter, options);
39
+            }
40
+            else if (expression is MemberExpression memberExpression)
41
+            {
42
+                if (memberExpression.Member.DeclaringType != typeof(TTypeFrom))
43
+                {
44
+                    return LuResult<Expression>.Error(LuStatus.InputError.ToInt(), "Bad member expression type");
45
+                }
46
+            }
47
+            else if (expression is MethodCallExpression methodCallExpression)
48
+            {
49
+                if (methodCallExpression.Object != null && methodCallExpression.Object.Type != typeof(TTypeFrom))
50
+                {
51
+                    return LuResult<Expression>.Error(LuStatus.InputError.ToInt(), "Bad method call expression type");
52
+                }
53
+            }
54
+
55
+            var convertResult = ConvertInternal(expressions, baseExpression, options);
56
+            return convertResult;
57
+        }
58
+
59
+        protected LuResult<Expression> ConvertOther(Type typeFrom, Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
60
+        {
61
+            var type = typeof(ILuExpressionConverter<>);
62
+            var gtype = type.MakeGenericType(typeFrom);
63
+            var converter = (ILuExpressionConverter) ServiceProvider.GetService(gtype);
64
+            if (converter == null)
65
+            {
66
+                return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(), $"Could not get service: {gtype}>");
67
+            }
68
+
69
+            return converter.ConvertExpression(expressions, baseExpression, options);
70
+        }
71
+
72
+        protected bool MemberMatch<TTypeFromProperty>(Expression<Func<TTypeFrom, TTypeFromProperty>> member, MemberExpression memberExpression)
73
+        {
74
+            return LuExpressionUtils.GetSingleMemberFromExpression(member) == memberExpression.Member;
75
+        }
76
+
77
+        protected LuResult<Expression> MakeMemberAccess<TTypeToProperty>(Expression<Func<TTypeTo, TTypeToProperty>> expression, Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
78
+        {
79
+            var exp = expressions.Pop();
80
+            var memberInfo = LuExpressionUtils.GetSingleMemberFromExpression(expression);
81
+            var newExpression = Expression.MakeMemberAccess(baseExpression, memberInfo);
82
+            var convertResult = ConvertOther(exp.Type, expressions, newExpression, options);
83
+            return convertResult;
84
+        }
85
+
86
+//        protected LuResult<Expression> MakeMethodCall<TTypeToProperty>(Expression<Func<TTypeTo, TTypeToProperty>> expression, Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
87
+//        {
88
+//            var exp = expressions.Pop();
89
+//        }
90
+
91
+        protected virtual LuResult<Expression> ConvertInternal(Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options)
92
+        {
93
+            return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(), "Not supported expression");
94
+        }
95
+    }
96
+}

+ 88
- 0
Luticate2.Auth/Business/Fields/LuExpressionConverterVisitor.cs 查看文件

@@ -0,0 +1,88 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq.Expressions;
4
+using Luticate2.Auth.Business.Fields.DMEC;
5
+using Luticate2.Auth.Dbo;
6
+using Luticate2.Auth.Dbo.Result;
7
+using Luticate2.Auth.Exceptions;
8
+using Luticate2.Auth.Interfaces;
9
+
10
+namespace Luticate2.Auth.Business.Fields
11
+{
12
+    public class LuExpressionConverterVisitor : ExpressionVisitor
13
+    {
14
+        public LuExpressionConverterOptions Options { get; }
15
+
16
+        protected IServiceProvider ServiceProvider { get; }
17
+
18
+        public LuExpressionConverterVisitor(LuExpressionConverterOptions options, IServiceProvider serviceProvider)
19
+        {
20
+            Options = options;
21
+            ServiceProvider = serviceProvider;
22
+        }
23
+
24
+        protected LuResult<Stack<Expression>> StackSimpleExpression(Expression expression, Stack<Expression> stack)
25
+        {
26
+            if (expression is ParameterExpression parameterExpression)
27
+            {
28
+                stack.Push(parameterExpression);
29
+                return LuResult<Stack<Expression>>.Ok(stack);
30
+            }
31
+            else if (expression is MemberExpression memberExpression)
32
+            {
33
+                stack.Push(memberExpression);
34
+                var result = StackSimpleExpression(memberExpression.Expression, stack);
35
+                return result;
36
+            }
37
+            else if (expression is MethodCallExpression methodCallExpression)
38
+            {
39
+                if (methodCallExpression.Object != null)
40
+                {
41
+                    stack.Push(methodCallExpression);
42
+                    var result = StackSimpleExpression(methodCallExpression.Object, stack);
43
+                    return result;
44
+                }
45
+                else
46
+                {
47
+                    stack.Push(methodCallExpression);
48
+                    var param = Expression.Parameter(typeof(LuExpressionConverterStaticMethods));
49
+                    stack.Push(param);
50
+                    return LuResult<Stack<Expression>>.Ok(stack);
51
+                }
52
+            }
53
+
54
+            return LuResult<Stack<Expression>>.Error(LuStatus.InternalError.ToInt(), "Invalid Simple Expression Member");
55
+        }
56
+
57
+        protected Expression ReplaceExpression(Expression expression)
58
+        {
59
+            var stackResult = StackSimpleExpression(expression, new Stack<Expression>()).ThrowIfNotSuccess();
60
+
61
+            var firstResult = stackResult.Data.Peek();
62
+
63
+            var type = typeof(ILuExpressionConverter<>);
64
+            var gtype = type.MakeGenericType(firstResult.Type);
65
+            var converter = (ILuExpressionConverter) ServiceProvider.GetService(gtype);
66
+            if (converter == null)
67
+            {
68
+                LuResult<Expression>.Error(LuStatus.InternalError.ToInt(), $"Could not get service: ILuExpressionConverter<{firstResult.Type.Name}>").Throw();
69
+            }
70
+
71
+            var exp = converter.ConvertExpression(stackResult.Data, null, Options).ThrowIfNotSuccess();
72
+
73
+            return exp.Data;
74
+        }
75
+
76
+        protected override Expression VisitMember(MemberExpression node)
77
+        {
78
+            return ReplaceExpression(node);
79
+        }
80
+
81
+        protected override Expression VisitMethodCall(MethodCallExpression node)
82
+        {
83
+            return ReplaceExpression(node);
84
+        }
85
+
86
+
87
+    }
88
+}

+ 0
- 24
Luticate2.Auth/Business/FieldsExpressions/Basic/LuFieldsExpressionsString.cs 查看文件

@@ -1,24 +0,0 @@
1
-using System;
2
-using System.Linq.Expressions;
3
-using Luticate2.Auth.Business.Fields;
4
-using Luticate2.Auth.Dbo.Fields;
5
-using Luticate2.Auth.Dbo.Result;
6
-
7
-namespace Luticate2.Auth.Business.FieldsExpressions.Basic
8
-{
9
-    public class LuFieldsExpressionsString : LuFieldsExpressions<string, string>
10
-    {
11
-        public LuFieldsExpressionsString(IServiceProvider serviceProvider) : base(serviceProvider)
12
-        {
13
-        }
14
-
15
-        protected override LuResult<Expression<Func<TType1, object>>> GetExpressionInternal<TType1>(Expression<Func<TType1, string>> modelProperty, LuFieldDbo field)
16
-        {
17
-            if (field.StartsWith<string>(x => x.Length))
18
-            {
19
-                return GetSubField<TType1, int, int>(modelProperty, field, x => x.Length);
20
-            }
21
-            return base.GetExpressionInternal(modelProperty, field);
22
-        }
23
-    }
24
-}

+ 0
- 60
Luticate2.Auth/Business/FieldsExpressions/LuFieldsExpressions.cs 查看文件

@@ -1,60 +0,0 @@
1
-using System;
2
-using System.Linq.Expressions;
3
-using Luticate2.Auth.Business.Fields;
4
-using Luticate2.Auth.Dbo;
5
-using Luticate2.Auth.Dbo.Fields;
6
-using Luticate2.Auth.Dbo.Result;
7
-using Luticate2.Auth.Interfaces;
8
-using Microsoft.Extensions.DependencyInjection;
9
-
10
-namespace Luticate2.Auth.Business.FieldsExpressions
11
-{
12
-    public class LuFieldsExpressions<TDbo, TModel> : ILuFieldsExpressions<TDbo, TModel>
13
-    {
14
-        protected IServiceProvider ServiceProvider { get; }
15
-
16
-        public LuFieldsExpressions(IServiceProvider serviceProvider)
17
-        {
18
-            ServiceProvider = serviceProvider;
19
-        }
20
-        
21
-        public ILuFieldsExpressions<TDbo2, TModel2> GetService<TDbo2, TModel2>()
22
-        {
23
-            var service = ServiceProvider.GetService<ILuFieldsExpressions<TDbo2, TModel2>>();
24
-            return service;
25
-        }
26
-
27
-        protected LuResult<Expression<Func<TType1, object>>> GetSubField<TType1, TType2, TType3>(
28
-            Expression<Func<TType1, TModel>> modelProperty, LuFieldDbo field, Expression<Func<TModel, TType3>> modelSubProperty)
29
-        {
30
-            var subPropExprResult = LuExpressionUtils.GetSingleMemberFromExpression(modelSubProperty);
31
-            if (subPropExprResult == null)
32
-            {
33
-                return LuResult<Expression<Func<TType1, object>>>.Error(LuStatus.InternalError.ToInt(), "Bad field expression");
34
-            }
35
-
36
-            var prop = Expression.Property(modelProperty.Body, subPropExprResult.Name);
37
-            var exp = Expression.Lambda<Func<TType1, TType3>>(prop, modelProperty.Parameters[0]);
38
-            var service = GetService<TType2, TType3>();
39
-            var finalExpResult = service.GetExpression(exp, field.Popped());
40
-            return finalExpResult;
41
-        }
42
-
43
-        protected virtual LuResult<Expression<Func<TType1, object>>> GetExpressionInternal<TType1>(
44
-            Expression<Func<TType1, TModel>> modelProperty, LuFieldDbo field)
45
-        {
46
-            return LuResult<Expression<Func<TType1, object>>>.Error(LuStatus.InputError.ToInt(), $"Unknown field: {field}", "");
47
-        }
48
-
49
-        public virtual LuResult<Expression<Func<TType1, object>>> GetExpression<TType1>(Expression<Func<TType1, TModel>> modelProperty, LuFieldDbo field)
50
-        {
51
-            if (field.IsRoot())
52
-            {
53
-                var converted = Expression.Convert(modelProperty.Body, typeof(object));
54
-                var exp = Expression.Lambda<Func<TType1, object>>(converted, modelProperty.Parameters[0]);
55
-                return LuResult<Expression<Func<TType1, object>>>.Ok(exp);
56
-            }
57
-            return GetExpressionInternal(modelProperty, field);
58
-        }
59
-    }
60
-}

+ 5
- 1
Luticate2.Auth/Business/Pagination/LuFilterParser.cs 查看文件

@@ -12,6 +12,10 @@ namespace Luticate2.Auth.Business.Pagination
12 12
     {
13 13
         public static LuResult<LuFilterDbo> Parse<T>(string data)
14 14
         {
15
+            if (string.IsNullOrWhiteSpace(data))
16
+            {
17
+                data = "true";
18
+            }
15 19
             var completeData = $"(x) => ({data})";
16 20
             try
17 21
             {
@@ -24,7 +28,7 @@ namespace Luticate2.Auth.Business.Pagination
24 28
             }
25 29
             catch (Exception e)
26 30
             {
27
-                return LuResult<LuFilterDbo>.Error(LuStatus.InputError.ToInt(), e);
31
+                return LuResult<LuFilterDbo>.Error(LuStatus.InputError.ToInt(), e, "Failed to parse filter expression");
28 32
             }
29 33
         }
30 34
     }

+ 20
- 0
Luticate2.Auth/Interfaces/ILuExpressionConverter.cs 查看文件

@@ -0,0 +1,20 @@
1
+using System.Collections.Generic;
2
+using System.Linq.Expressions;
3
+using Luticate2.Auth.Business.Fields.DMEC;
4
+using Luticate2.Auth.Dbo.Result;
5
+
6
+namespace Luticate2.Auth.Interfaces
7
+{
8
+    public interface ILuExpressionConverter
9
+    {
10
+        LuResult<Expression> ConvertExpression(Stack<Expression> expressions, Expression baseExpression, LuExpressionConverterOptions options);
11
+    }
12
+
13
+    public interface ILuExpressionConverter<TTypeFrom> : ILuExpressionConverter
14
+    {
15
+    }
16
+
17
+    public interface ILuExpressionConverter<TTypeFrom, TTypeTo> : ILuExpressionConverter<TTypeFrom>
18
+    {
19
+    }
20
+}

+ 0
- 12
Luticate2.Auth/Interfaces/ILuFieldsExpressions.cs 查看文件

@@ -1,12 +0,0 @@
1
-using System;
2
-using System.Linq.Expressions;
3
-using Luticate2.Auth.Dbo.Fields;
4
-using Luticate2.Auth.Dbo.Result;
5
-
6
-namespace Luticate2.Auth.Interfaces
7
-{
8
-    public interface ILuFieldsExpressions<TDbo, TModel>
9
-    {
10
-        LuResult<Expression<Func<TType1, object>>> GetExpression<TType1>(Expression<Func<TType1, TModel>> modelProperty, LuFieldDbo field);
11
-    }
12
-}

正在加载...
取消
保存