Kaynağa Gözat

Removed unused imports; Added new interfaces for LuConvertersOptions

develop
Robin Thoni 6 yıl önce
ebeveyn
işleme
48abfaddaf

+ 0
- 2
Luticate2.Auth.ConsoleSample/Program.cs Dosyayı Görüntüle

@@ -1,8 +1,6 @@
1 1
 using System;
2 2
 using Luticate2.Auth.Auth.Business;
3 3
 using Luticate2.Auth.Auth.DataAccess;
4
-using Luticate2.Auth.Auth.DataAccess.Models;
5
-using Luticate2.Auth.Auth.Dbo;
6 4
 using Luticate2.Auth.ConsoleSample.Commands;
7 5
 using Microsoft.EntityFrameworkCore;
8 6
 using Microsoft.Extensions.DependencyInjection;

+ 1
- 1
Luticate2.Auth.Tests/Business/ExpressionConverter/ExpressionConverterTests.cs Dosyayı Görüntüle

@@ -30,7 +30,7 @@ namespace Luticate2.Auth.Tests.Business.ExpressionConverter
30 30
             return serviceProvider;
31 31
         }
32 32
 
33
-        protected LuConvertersOptions GetConverterOptions()
33
+        protected ILuExpressionConverterVisitorOptions GetConverterOptions()
34 34
         {
35 35
             var options = new LuConvertersOptions
36 36
             {

+ 1
- 1
Luticate2.Auth.Tests/Business/ObjectConverter/ObjectConverterTests.cs Dosyayı Görüntüle

@@ -62,7 +62,7 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
62 62
             return serviceProvider;
63 63
         }
64 64
 
65
-        protected LuConvertersOptions GetConverterOptions()
65
+        protected ILuObjectConverterOptions GetConverterOptions()
66 66
         {
67 67
             var options = new LuConvertersOptions
68 68
             {

+ 1
- 2
Luticate2.Auth.Tests/RandomTests.cs Dosyayı Görüntüle

@@ -1,5 +1,4 @@
1
-using Luticate2.Auth.Utils.Business.ObjectConverter;
2
-using Xunit;
1
+using Xunit;
3 2
 
4 3
 namespace Luticate2.Auth.Tests
5 4
 {

+ 0
- 1
Luticate2.Auth/Utils/Business/Converters/LuConvertersAllocator.cs Dosyayı Görüntüle

@@ -1,5 +1,4 @@
1 1
 using System;
2
-using System.Collections;
3 2
 using System.Collections.Generic;
4 3
 using System.Collections.ObjectModel;
5 4
 using Luticate2.Auth.Utils.Interfaces;

+ 7
- 1
Luticate2.Auth/Utils/Business/Converters/LuConvertersOptions.cs Dosyayı Görüntüle

@@ -1,15 +1,21 @@
1 1
 using System.Collections.Generic;
2 2
 using System.Linq.Expressions;
3
+using Luticate2.Auth.Utils.Business.ExpressionConverter;
3 4
 using Luticate2.Auth.Utils.Interfaces;
4 5
 
5 6
 namespace Luticate2.Auth.Utils.Business.Converters
6 7
 {
7
-    public class LuConvertersOptions
8
+    public class LuConvertersOptions : ILuObjectConverterOptions, ILuObjectConverterDescriptorOptions,
9
+        ILuExpressionConverterVisitorOptions, ILuExpressionParamReplaceVisitorOptions
8 10
     {
9 11
         public IDictionary<ParameterExpression, Expression> Parameters { get; set; }
10 12
 
11 13
         public ILuConvertersTypeConverter TypeConverter { get; set; }
12 14
 
13 15
         public ILuConvertersAllocator Allocator { get; set; }
16
+
17
+        public ILuObjectConverterDescriptorOptions DescriptorOptions => this;
18
+
19
+        public ILuExpressionParamReplaceVisitorOptions VisitorOptions => this;
14 20
     }
15 21
 }

+ 1
- 1
Luticate2.Auth/Utils/Business/Crud/LuEfCrudBusiness.cs Dosyayı Görüntüle

@@ -26,7 +26,7 @@ namespace Luticate2.Auth.Utils.Business.Crud
26 26
             ServiceProvider = serviceProvider;
27 27
         }
28 28
 
29
-        protected virtual LuConvertersOptions GetOptions()
29
+        protected virtual ILuObjectConverterOptions GetOptions()
30 30
         {
31 31
             return new LuConvertersOptions();// TODO
32 32
         }

+ 17
- 7
Luticate2.Auth/Utils/Business/ExpressionConverter/LuExpressionConverterVisitor.cs Dosyayı Görüntüle

@@ -3,7 +3,6 @@ using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Linq.Expressions;
5 5
 using Luticate2.Auth.Utils.Business.Converters;
6
-using Luticate2.Auth.Utils.Business.Utils;
7 6
 using Luticate2.Auth.Utils.Dbo;
8 7
 using Luticate2.Auth.Utils.Dbo.Result;
9 8
 using Luticate2.Auth.Utils.Exceptions;
@@ -11,13 +10,24 @@ using Luticate2.Auth.Utils.Interfaces;
11 10
 
12 11
 namespace Luticate2.Auth.Utils.Business.ExpressionConverter
13 12
 {
13
+    public interface ILuExpressionConverterVisitorOptions
14
+    {
15
+        IDictionary<ParameterExpression, Expression> Parameters { get; }
16
+
17
+        ILuConvertersTypeConverter TypeConverter { get; }
18
+
19
+        ILuObjectConverterDescriptorOptions DescriptorOptions { get; }
20
+
21
+        ILuExpressionParamReplaceVisitorOptions VisitorOptions { get; }
22
+    }
23
+
14 24
     public class LuExpressionConverterVisitor : ExpressionVisitor
15 25
     {
16
-        public LuConvertersOptions Options { get; }
26
+        public ILuExpressionConverterVisitorOptions Options { get; }
17 27
 
18 28
         protected IServiceProvider ServiceProvider { get; }
19 29
 
20
-        public LuExpressionConverterVisitor(LuConvertersOptions options, IServiceProvider serviceProvider)
30
+        public LuExpressionConverterVisitor(ILuExpressionConverterVisitorOptions options, IServiceProvider serviceProvider)
21 31
         {
22 32
             Options = options;
23 33
             ServiceProvider = serviceProvider;
@@ -72,7 +82,7 @@ namespace Luticate2.Auth.Utils.Business.ExpressionConverter
72 82
                     $"Could not find converter descriptor for {typeFrom} => {typeTo}");
73 83
             }
74 84
 
75
-            var valueExpression = descriptor.GetMemberValueExpression(memberExpression.Member, Options);
85
+            var valueExpression = descriptor.GetMemberValueExpression(memberExpression.Member, Options.DescriptorOptions);
76 86
             if (valueExpression == null)
77 87
             {
78 88
                 return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(),
@@ -89,7 +99,7 @@ namespace Luticate2.Auth.Utils.Business.ExpressionConverter
89 99
                 Options.Parameters.Add(valueExpression.Parameters[0], newExpression);
90 100
             }
91 101
 
92
-            var visitor = new LuExpressionParamReplaceVisitor(Options);
102
+            var visitor = new LuExpressionParamReplaceVisitor(Options.VisitorOptions);
93 103
             newExpression = visitor.Visit(valueExpression.Body);
94 104
 
95 105
             if (newExpression != null)
@@ -110,7 +120,7 @@ namespace Luticate2.Auth.Utils.Business.ExpressionConverter
110 120
                     $"Could not find converter descriptor for {typeFrom} => {typeTo}");
111 121
             }
112 122
 
113
-            var valueExpression = descriptor.GetMethodValueExpression(methodCallExpression.Method, Options);
123
+            var valueExpression = descriptor.GetMethodValueExpression(methodCallExpression.Method, Options.DescriptorOptions);
114 124
             if (valueExpression == null)
115 125
             {
116 126
                 return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(),
@@ -134,7 +144,7 @@ namespace Luticate2.Auth.Utils.Business.ExpressionConverter
134 144
                 Options.Parameters.Add(valueExpression.Parameters[i + 1], convertedArgument);
135 145
             }
136 146
             Options.Parameters.Add(valueExpression.Parameters[0], newExpression);
137
-            var visitor = new LuExpressionParamReplaceVisitor(Options);
147
+            var visitor = new LuExpressionParamReplaceVisitor(Options.VisitorOptions);
138 148
             newExpression = visitor.Visit(valueExpression.Body);
139 149
             Options.Parameters.Remove(valueExpression.Parameters[0]);
140 150
 

+ 8
- 2
Luticate2.Auth/Utils/Business/ExpressionConverter/LuExpressionParamReplaceVisitor.cs Dosyayı Görüntüle

@@ -1,3 +1,4 @@
1
+using System.Collections.Generic;
1 2
 using System.Linq.Expressions;
2 3
 using Luticate2.Auth.Utils.Business.Converters;
3 4
 using Luticate2.Auth.Utils.Dbo;
@@ -6,11 +7,16 @@ using Luticate2.Auth.Utils.Exceptions;
6 7
 
7 8
 namespace Luticate2.Auth.Utils.Business.ExpressionConverter
8 9
 {
10
+    public interface ILuExpressionParamReplaceVisitorOptions
11
+    {
12
+        IDictionary<ParameterExpression, Expression> Parameters { get; }
13
+    }
14
+
9 15
     public class LuExpressionParamReplaceVisitor : ExpressionVisitor
10 16
     {
11
-        public LuConvertersOptions Options { get; }
17
+        public ILuExpressionParamReplaceVisitorOptions Options { get; }
12 18
 
13
-        public LuExpressionParamReplaceVisitor(LuConvertersOptions options)
19
+        public LuExpressionParamReplaceVisitor(ILuExpressionParamReplaceVisitorOptions options)
14 20
         {
15 21
             Options = options;
16 22
         }

+ 1
- 2
Luticate2.Auth/Utils/Business/ObjectConverter/LuObjectConverterIdentity.cs Dosyayı Görüntüle

@@ -1,4 +1,3 @@
1
-using Luticate2.Auth.Utils.Business.Converters;
2 1
 using Luticate2.Auth.Utils.Dbo.Fields;
3 2
 using Luticate2.Auth.Utils.Dbo.Result;
4 3
 using Luticate2.Auth.Utils.Interfaces;
@@ -7,7 +6,7 @@ namespace Luticate2.Auth.Utils.Business.ObjectConverter
7 6
 {
8 7
     public class LuObjectConverterIdentity : ILuObjectConverterIdentity
9 8
     {
10
-        public LuResult<object> Convert(object srcObj, LuPartialFieldsDbo fields, LuConvertersOptions options)
9
+        public LuResult<object> Convert(object srcObj, LuPartialFieldsDbo fields, ILuObjectConverterOptions options)
11 10
         {
12 11
             return LuResult<object>.Ok(srcObj);
13 12
         }

+ 1
- 2
Luticate2.Auth/Utils/Business/ObjectConverter/LuObjectConverterLists.cs Dosyayı Görüntüle

@@ -2,7 +2,6 @@ using System;
2 2
 using System.Collections;
3 3
 using System.Collections.Generic;
4 4
 using System.Collections.ObjectModel;
5
-using Luticate2.Auth.Utils.Business.Converters;
6 5
 using Luticate2.Auth.Utils.Dbo;
7 6
 using Luticate2.Auth.Utils.Dbo.Fields;
8 7
 using Luticate2.Auth.Utils.Dbo.Result;
@@ -21,7 +20,7 @@ namespace Luticate2.Auth.Utils.Business.ObjectConverter
21 20
 
22 21
         protected abstract Type GetListType();
23 22
 
24
-        public LuResult<object> Convert(object srcObj, LuPartialFieldsDbo fields, LuConvertersOptions options)
23
+        public LuResult<object> Convert(object srcObj, LuPartialFieldsDbo fields, ILuObjectConverterOptions options)
25 24
         {
26 25
             if (srcObj is IEnumerable enumerable)
27 26
             {

+ 2
- 3
Luticate2.Auth/Utils/Business/ObjectConverter/LuObjectConverterPoco.cs Dosyayı Görüntüle

@@ -1,5 +1,4 @@
1 1
 using System;
2
-using Luticate2.Auth.Utils.Business.Converters;
3 2
 using Luticate2.Auth.Utils.Business.Utils;
4 3
 using Luticate2.Auth.Utils.Dbo.Fields;
5 4
 using Luticate2.Auth.Utils.Dbo.Result;
@@ -17,7 +16,7 @@ namespace Luticate2.Auth.Utils.Business.ObjectConverter
17 16
             ServiceProvider = serviceProvider;
18 17
         }
19 18
 
20
-        public LuResult<object> Convert(object srcObj, LuPartialFieldsDbo fields, LuConvertersOptions options)
19
+        public LuResult<object> Convert(object srcObj, LuPartialFieldsDbo fields, ILuObjectConverterOptions options)
21 20
         {
22 21
             // TODO Check if this is correct
23 22
             if (srcObj == null)
@@ -33,7 +32,7 @@ namespace Luticate2.Auth.Utils.Business.ObjectConverter
33 32
             {
34 33
                 // TODO check if field is included in fields
35 34
                 // TODO Handle srcPropExpression == null
36
-                var srcPropExpression = descriptor.GetMemberValueExpression(memberInfo, options);
35
+                var srcPropExpression = descriptor.GetMemberValueExpression(memberInfo, options.DescriptorOptions);
37 36
                 var srcPropDelegate = srcPropExpression.Compile();
38 37
                 var srcProp = srcPropDelegate.DynamicInvoke(srcObj);
39 38
                 var srcType = srcProp != null ? srcProp.GetType() : srcPropExpression.ReturnType;

+ 2
- 4
Luticate2.Auth/Utils/Business/ObjectConverterDescriptor/LuObjectConverterDescriptor.cs Dosyayı Görüntüle

@@ -3,8 +3,6 @@ using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Linq.Expressions;
5 5
 using System.Reflection;
6
-using Luticate2.Auth.Utils.Business.Converters;
7
-using Luticate2.Auth.Utils.Business.ExpressionConverter;
8 6
 using Luticate2.Auth.Utils.Business.Utils;
9 7
 using Luticate2.Auth.Utils.Interfaces;
10 8
 
@@ -84,7 +82,7 @@ namespace Luticate2.Auth.Utils.Business.ObjectConverterDescriptor
84 82
             );
85 83
         }
86 84
 
87
-        public LambdaExpression GetMemberValueExpression(MemberInfo memberInfo, LuConvertersOptions options)
85
+        public LambdaExpression GetMemberValueExpression(MemberInfo memberInfo, ILuObjectConverterDescriptorOptions options)
88 86
         {
89 87
             if (StaticMemberConverters.ContainsKey(memberInfo))
90 88
             {
@@ -94,7 +92,7 @@ namespace Luticate2.Auth.Utils.Business.ObjectConverterDescriptor
94 92
             return null;
95 93
         }
96 94
 
97
-        public LambdaExpression GetMethodValueExpression(MethodInfo methodInfo, LuConvertersOptions options)
95
+        public LambdaExpression GetMethodValueExpression(MethodInfo methodInfo, ILuObjectConverterDescriptorOptions options)
98 96
         {
99 97
             if (StaticMethodConverters.ContainsKey(methodInfo))
100 98
             {

+ 2
- 4
Luticate2.Auth/Utils/Business/ObjectConverterDescriptor/LuObjectConverterDescriptorIdentity.cs Dosyayı Görüntüle

@@ -2,15 +2,13 @@ using System.Collections.Generic;
2 2
 using System.Linq;
3 3
 using System.Linq.Expressions;
4 4
 using System.Reflection;
5
-using Luticate2.Auth.Utils.Business.Converters;
6
-using Luticate2.Auth.Utils.Business.ExpressionConverter;
7 5
 using Luticate2.Auth.Utils.Interfaces;
8 6
 
9 7
 namespace Luticate2.Auth.Utils.Business.ObjectConverterDescriptor
10 8
 {
11 9
     public class LuObjectConverterDescriptorIdentity : ILuObjectConverterDescriptorIdentity
12 10
     {
13
-        public LambdaExpression GetMemberValueExpression(MemberInfo memberInfo, LuConvertersOptions options)
11
+        public LambdaExpression GetMemberValueExpression(MemberInfo memberInfo, ILuObjectConverterDescriptorOptions options)
14 12
         {
15 13
             var isStatic = false;
16 14
             if (memberInfo is FieldInfo fieldInfo)
@@ -27,7 +25,7 @@ namespace Luticate2.Auth.Utils.Business.ObjectConverterDescriptor
27 25
             return lambda;
28 26
         }
29 27
 
30
-        public LambdaExpression GetMethodValueExpression(MethodInfo methodInfo, LuConvertersOptions options)
28
+        public LambdaExpression GetMethodValueExpression(MethodInfo methodInfo, ILuObjectConverterDescriptorOptions options)
31 29
         {
32 30
             var lambdaParams = new List<ParameterExpression>
33 31
             {

+ 0
- 1
Luticate2.Auth/Utils/Dbo/Fields/LuFieldDbo.cs Dosyayı Görüntüle

@@ -1,6 +1,5 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
-using System.Linq;
4 3
 using System.Linq.Expressions;
5 4
 using Luticate2.Auth.Utils.Business.Fields;
6 5
 

+ 10
- 3
Luticate2.Auth/Utils/Interfaces/ILuObjectConverter.cs Dosyayı Görüntüle

@@ -1,13 +1,20 @@
1
-using Luticate2.Auth.Utils.Business.Converters;
2
-using Luticate2.Auth.Utils.Business.ExpressionConverter;
3 1
 using Luticate2.Auth.Utils.Dbo.Fields;
4 2
 using Luticate2.Auth.Utils.Dbo.Result;
5 3
 
6 4
 namespace Luticate2.Auth.Utils.Interfaces
7 5
 {
6
+    public interface ILuObjectConverterOptions
7
+    {
8
+        ILuConvertersTypeConverter TypeConverter { get; }
9
+
10
+        ILuConvertersAllocator Allocator { get; }
11
+
12
+        ILuObjectConverterDescriptorOptions DescriptorOptions { get; }
13
+    }
14
+
8 15
     public interface ILuObjectConverter
9 16
     {
10
-        LuResult<object> Convert(object srcObj, LuPartialFieldsDbo fields, LuConvertersOptions options);
17
+        LuResult<object> Convert(object srcObj, LuPartialFieldsDbo fields, ILuObjectConverterOptions options);
11 18
     }
12 19
 
13 20
     public interface ILuObjectConverter<TTypeFrom, TTypeTo> : ILuObjectConverter

+ 7
- 4
Luticate2.Auth/Utils/Interfaces/ILuObjectConverterDescriptor.cs Dosyayı Görüntüle

@@ -1,15 +1,18 @@
1 1
 using System.Linq.Expressions;
2 2
 using System.Reflection;
3
-using Luticate2.Auth.Utils.Business.Converters;
4
-using Luticate2.Auth.Utils.Business.ExpressionConverter;
5 3
 
6 4
 namespace Luticate2.Auth.Utils.Interfaces
7 5
 {
6
+    public interface ILuObjectConverterDescriptorOptions
7
+    {
8
+        ILuConvertersTypeConverter TypeConverter { get; }
9
+    }
10
+
8 11
     public interface ILuObjectConverterDescriptor
9 12
     {
10
-        LambdaExpression GetMemberValueExpression(MemberInfo memberInfo, LuConvertersOptions options);
13
+        LambdaExpression GetMemberValueExpression(MemberInfo memberInfo, ILuObjectConverterDescriptorOptions options);
11 14
 
12
-        LambdaExpression GetMethodValueExpression(MethodInfo methodInfo, LuConvertersOptions options);
15
+        LambdaExpression GetMethodValueExpression(MethodInfo methodInfo, ILuObjectConverterDescriptorOptions options);
13 16
     }
14 17
 
15 18
     public interface ILuObjectConverterDescriptor<TTypeFrom, TTypeTo> : ILuObjectConverterDescriptor

Loading…
İptal
Kaydet