소스 검색

Removed unused imports; Added new interfaces for LuConvertersOptions

develop
Robin Thoni 5 년 전
부모
커밋
48abfaddaf

+ 0
- 2
Luticate2.Auth.ConsoleSample/Program.cs 파일 보기

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

+ 1
- 1
Luticate2.Auth.Tests/Business/ExpressionConverter/ExpressionConverterTests.cs 파일 보기

30
             return serviceProvider;
30
             return serviceProvider;
31
         }
31
         }
32
 
32
 
33
-        protected LuConvertersOptions GetConverterOptions()
33
+        protected ILuExpressionConverterVisitorOptions GetConverterOptions()
34
         {
34
         {
35
             var options = new LuConvertersOptions
35
             var options = new LuConvertersOptions
36
             {
36
             {

+ 1
- 1
Luticate2.Auth.Tests/Business/ObjectConverter/ObjectConverterTests.cs 파일 보기

62
             return serviceProvider;
62
             return serviceProvider;
63
         }
63
         }
64
 
64
 
65
-        protected LuConvertersOptions GetConverterOptions()
65
+        protected ILuObjectConverterOptions GetConverterOptions()
66
         {
66
         {
67
             var options = new LuConvertersOptions
67
             var options = new LuConvertersOptions
68
             {
68
             {

+ 1
- 2
Luticate2.Auth.Tests/RandomTests.cs 파일 보기

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

+ 0
- 1
Luticate2.Auth/Utils/Business/Converters/LuConvertersAllocator.cs 파일 보기

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

+ 7
- 1
Luticate2.Auth/Utils/Business/Converters/LuConvertersOptions.cs 파일 보기

1
 using System.Collections.Generic;
1
 using System.Collections.Generic;
2
 using System.Linq.Expressions;
2
 using System.Linq.Expressions;
3
+using Luticate2.Auth.Utils.Business.ExpressionConverter;
3
 using Luticate2.Auth.Utils.Interfaces;
4
 using Luticate2.Auth.Utils.Interfaces;
4
 
5
 
5
 namespace Luticate2.Auth.Utils.Business.Converters
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
         public IDictionary<ParameterExpression, Expression> Parameters { get; set; }
11
         public IDictionary<ParameterExpression, Expression> Parameters { get; set; }
10
 
12
 
11
         public ILuConvertersTypeConverter TypeConverter { get; set; }
13
         public ILuConvertersTypeConverter TypeConverter { get; set; }
12
 
14
 
13
         public ILuConvertersAllocator Allocator { get; set; }
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 파일 보기

26
             ServiceProvider = serviceProvider;
26
             ServiceProvider = serviceProvider;
27
         }
27
         }
28
 
28
 
29
-        protected virtual LuConvertersOptions GetOptions()
29
+        protected virtual ILuObjectConverterOptions GetOptions()
30
         {
30
         {
31
             return new LuConvertersOptions();// TODO
31
             return new LuConvertersOptions();// TODO
32
         }
32
         }

+ 17
- 7
Luticate2.Auth/Utils/Business/ExpressionConverter/LuExpressionConverterVisitor.cs 파일 보기

3
 using System.Linq;
3
 using System.Linq;
4
 using System.Linq.Expressions;
4
 using System.Linq.Expressions;
5
 using Luticate2.Auth.Utils.Business.Converters;
5
 using Luticate2.Auth.Utils.Business.Converters;
6
-using Luticate2.Auth.Utils.Business.Utils;
7
 using Luticate2.Auth.Utils.Dbo;
6
 using Luticate2.Auth.Utils.Dbo;
8
 using Luticate2.Auth.Utils.Dbo.Result;
7
 using Luticate2.Auth.Utils.Dbo.Result;
9
 using Luticate2.Auth.Utils.Exceptions;
8
 using Luticate2.Auth.Utils.Exceptions;
11
 
10
 
12
 namespace Luticate2.Auth.Utils.Business.ExpressionConverter
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
     public class LuExpressionConverterVisitor : ExpressionVisitor
24
     public class LuExpressionConverterVisitor : ExpressionVisitor
15
     {
25
     {
16
-        public LuConvertersOptions Options { get; }
26
+        public ILuExpressionConverterVisitorOptions Options { get; }
17
 
27
 
18
         protected IServiceProvider ServiceProvider { get; }
28
         protected IServiceProvider ServiceProvider { get; }
19
 
29
 
20
-        public LuExpressionConverterVisitor(LuConvertersOptions options, IServiceProvider serviceProvider)
30
+        public LuExpressionConverterVisitor(ILuExpressionConverterVisitorOptions options, IServiceProvider serviceProvider)
21
         {
31
         {
22
             Options = options;
32
             Options = options;
23
             ServiceProvider = serviceProvider;
33
             ServiceProvider = serviceProvider;
72
                     $"Could not find converter descriptor for {typeFrom} => {typeTo}");
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
             if (valueExpression == null)
86
             if (valueExpression == null)
77
             {
87
             {
78
                 return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(),
88
                 return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(),
89
                 Options.Parameters.Add(valueExpression.Parameters[0], newExpression);
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
             newExpression = visitor.Visit(valueExpression.Body);
103
             newExpression = visitor.Visit(valueExpression.Body);
94
 
104
 
95
             if (newExpression != null)
105
             if (newExpression != null)
110
                     $"Could not find converter descriptor for {typeFrom} => {typeTo}");
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
             if (valueExpression == null)
124
             if (valueExpression == null)
115
             {
125
             {
116
                 return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(),
126
                 return LuResult<Expression>.Error(LuStatus.InternalError.ToInt(),
134
                 Options.Parameters.Add(valueExpression.Parameters[i + 1], convertedArgument);
144
                 Options.Parameters.Add(valueExpression.Parameters[i + 1], convertedArgument);
135
             }
145
             }
136
             Options.Parameters.Add(valueExpression.Parameters[0], newExpression);
146
             Options.Parameters.Add(valueExpression.Parameters[0], newExpression);
137
-            var visitor = new LuExpressionParamReplaceVisitor(Options);
147
+            var visitor = new LuExpressionParamReplaceVisitor(Options.VisitorOptions);
138
             newExpression = visitor.Visit(valueExpression.Body);
148
             newExpression = visitor.Visit(valueExpression.Body);
139
             Options.Parameters.Remove(valueExpression.Parameters[0]);
149
             Options.Parameters.Remove(valueExpression.Parameters[0]);
140
 
150
 

+ 8
- 2
Luticate2.Auth/Utils/Business/ExpressionConverter/LuExpressionParamReplaceVisitor.cs 파일 보기

1
+using System.Collections.Generic;
1
 using System.Linq.Expressions;
2
 using System.Linq.Expressions;
2
 using Luticate2.Auth.Utils.Business.Converters;
3
 using Luticate2.Auth.Utils.Business.Converters;
3
 using Luticate2.Auth.Utils.Dbo;
4
 using Luticate2.Auth.Utils.Dbo;
6
 
7
 
7
 namespace Luticate2.Auth.Utils.Business.ExpressionConverter
8
 namespace Luticate2.Auth.Utils.Business.ExpressionConverter
8
 {
9
 {
10
+    public interface ILuExpressionParamReplaceVisitorOptions
11
+    {
12
+        IDictionary<ParameterExpression, Expression> Parameters { get; }
13
+    }
14
+
9
     public class LuExpressionParamReplaceVisitor : ExpressionVisitor
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
             Options = options;
21
             Options = options;
16
         }
22
         }

+ 1
- 2
Luticate2.Auth/Utils/Business/ObjectConverter/LuObjectConverterIdentity.cs 파일 보기

1
-using Luticate2.Auth.Utils.Business.Converters;
2
 using Luticate2.Auth.Utils.Dbo.Fields;
1
 using Luticate2.Auth.Utils.Dbo.Fields;
3
 using Luticate2.Auth.Utils.Dbo.Result;
2
 using Luticate2.Auth.Utils.Dbo.Result;
4
 using Luticate2.Auth.Utils.Interfaces;
3
 using Luticate2.Auth.Utils.Interfaces;
7
 {
6
 {
8
     public class LuObjectConverterIdentity : ILuObjectConverterIdentity
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
             return LuResult<object>.Ok(srcObj);
11
             return LuResult<object>.Ok(srcObj);
13
         }
12
         }

+ 1
- 2
Luticate2.Auth/Utils/Business/ObjectConverter/LuObjectConverterLists.cs 파일 보기

2
 using System.Collections;
2
 using System.Collections;
3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
 using System.Collections.ObjectModel;
4
 using System.Collections.ObjectModel;
5
-using Luticate2.Auth.Utils.Business.Converters;
6
 using Luticate2.Auth.Utils.Dbo;
5
 using Luticate2.Auth.Utils.Dbo;
7
 using Luticate2.Auth.Utils.Dbo.Fields;
6
 using Luticate2.Auth.Utils.Dbo.Fields;
8
 using Luticate2.Auth.Utils.Dbo.Result;
7
 using Luticate2.Auth.Utils.Dbo.Result;
21
 
20
 
22
         protected abstract Type GetListType();
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
             if (srcObj is IEnumerable enumerable)
25
             if (srcObj is IEnumerable enumerable)
27
             {
26
             {

+ 2
- 3
Luticate2.Auth/Utils/Business/ObjectConverter/LuObjectConverterPoco.cs 파일 보기

1
 using System;
1
 using System;
2
-using Luticate2.Auth.Utils.Business.Converters;
3
 using Luticate2.Auth.Utils.Business.Utils;
2
 using Luticate2.Auth.Utils.Business.Utils;
4
 using Luticate2.Auth.Utils.Dbo.Fields;
3
 using Luticate2.Auth.Utils.Dbo.Fields;
5
 using Luticate2.Auth.Utils.Dbo.Result;
4
 using Luticate2.Auth.Utils.Dbo.Result;
17
             ServiceProvider = serviceProvider;
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
             // TODO Check if this is correct
21
             // TODO Check if this is correct
23
             if (srcObj == null)
22
             if (srcObj == null)
33
             {
32
             {
34
                 // TODO check if field is included in fields
33
                 // TODO check if field is included in fields
35
                 // TODO Handle srcPropExpression == null
34
                 // TODO Handle srcPropExpression == null
36
-                var srcPropExpression = descriptor.GetMemberValueExpression(memberInfo, options);
35
+                var srcPropExpression = descriptor.GetMemberValueExpression(memberInfo, options.DescriptorOptions);
37
                 var srcPropDelegate = srcPropExpression.Compile();
36
                 var srcPropDelegate = srcPropExpression.Compile();
38
                 var srcProp = srcPropDelegate.DynamicInvoke(srcObj);
37
                 var srcProp = srcPropDelegate.DynamicInvoke(srcObj);
39
                 var srcType = srcProp != null ? srcProp.GetType() : srcPropExpression.ReturnType;
38
                 var srcType = srcProp != null ? srcProp.GetType() : srcPropExpression.ReturnType;

+ 2
- 4
Luticate2.Auth/Utils/Business/ObjectConverterDescriptor/LuObjectConverterDescriptor.cs 파일 보기

3
 using System.Linq;
3
 using System.Linq;
4
 using System.Linq.Expressions;
4
 using System.Linq.Expressions;
5
 using System.Reflection;
5
 using System.Reflection;
6
-using Luticate2.Auth.Utils.Business.Converters;
7
-using Luticate2.Auth.Utils.Business.ExpressionConverter;
8
 using Luticate2.Auth.Utils.Business.Utils;
6
 using Luticate2.Auth.Utils.Business.Utils;
9
 using Luticate2.Auth.Utils.Interfaces;
7
 using Luticate2.Auth.Utils.Interfaces;
10
 
8
 
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
             if (StaticMemberConverters.ContainsKey(memberInfo))
87
             if (StaticMemberConverters.ContainsKey(memberInfo))
90
             {
88
             {
94
             return null;
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
             if (StaticMethodConverters.ContainsKey(methodInfo))
97
             if (StaticMethodConverters.ContainsKey(methodInfo))
100
             {
98
             {

+ 2
- 4
Luticate2.Auth/Utils/Business/ObjectConverterDescriptor/LuObjectConverterDescriptorIdentity.cs 파일 보기

2
 using System.Linq;
2
 using System.Linq;
3
 using System.Linq.Expressions;
3
 using System.Linq.Expressions;
4
 using System.Reflection;
4
 using System.Reflection;
5
-using Luticate2.Auth.Utils.Business.Converters;
6
-using Luticate2.Auth.Utils.Business.ExpressionConverter;
7
 using Luticate2.Auth.Utils.Interfaces;
5
 using Luticate2.Auth.Utils.Interfaces;
8
 
6
 
9
 namespace Luticate2.Auth.Utils.Business.ObjectConverterDescriptor
7
 namespace Luticate2.Auth.Utils.Business.ObjectConverterDescriptor
10
 {
8
 {
11
     public class LuObjectConverterDescriptorIdentity : ILuObjectConverterDescriptorIdentity
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
             var isStatic = false;
13
             var isStatic = false;
16
             if (memberInfo is FieldInfo fieldInfo)
14
             if (memberInfo is FieldInfo fieldInfo)
27
             return lambda;
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
             var lambdaParams = new List<ParameterExpression>
30
             var lambdaParams = new List<ParameterExpression>
33
             {
31
             {

+ 0
- 1
Luticate2.Auth/Utils/Dbo/Fields/LuFieldDbo.cs 파일 보기

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

+ 10
- 3
Luticate2.Auth/Utils/Interfaces/ILuObjectConverter.cs 파일 보기

1
-using Luticate2.Auth.Utils.Business.Converters;
2
-using Luticate2.Auth.Utils.Business.ExpressionConverter;
3
 using Luticate2.Auth.Utils.Dbo.Fields;
1
 using Luticate2.Auth.Utils.Dbo.Fields;
4
 using Luticate2.Auth.Utils.Dbo.Result;
2
 using Luticate2.Auth.Utils.Dbo.Result;
5
 
3
 
6
 namespace Luticate2.Auth.Utils.Interfaces
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
     public interface ILuObjectConverter
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
     public interface ILuObjectConverter<TTypeFrom, TTypeTo> : ILuObjectConverter
20
     public interface ILuObjectConverter<TTypeFrom, TTypeTo> : ILuObjectConverter

+ 7
- 4
Luticate2.Auth/Utils/Interfaces/ILuObjectConverterDescriptor.cs 파일 보기

1
 using System.Linq.Expressions;
1
 using System.Linq.Expressions;
2
 using System.Reflection;
2
 using System.Reflection;
3
-using Luticate2.Auth.Utils.Business.Converters;
4
-using Luticate2.Auth.Utils.Business.ExpressionConverter;
5
 
3
 
6
 namespace Luticate2.Auth.Utils.Interfaces
4
 namespace Luticate2.Auth.Utils.Interfaces
7
 {
5
 {
6
+    public interface ILuObjectConverterDescriptorOptions
7
+    {
8
+        ILuConvertersTypeConverter TypeConverter { get; }
9
+    }
10
+
8
     public interface ILuObjectConverterDescriptor
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
     public interface ILuObjectConverterDescriptor<TTypeFrom, TTypeTo> : ILuObjectConverterDescriptor
18
     public interface ILuObjectConverterDescriptor<TTypeFrom, TTypeTo> : ILuObjectConverterDescriptor

Loading…
취소
저장