Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

LuExpressionConverterIdentity.cs 1.6KB

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