You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuExpressionParamReplaceVisitor.cs 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.Collections.Generic;
  2. using System.Linq.Expressions;
  3. using Luticate2.Auth.Utils.Dbo;
  4. using Luticate2.Auth.Utils.Dbo.Result;
  5. using Luticate2.Auth.Utils.Exceptions;
  6. namespace Luticate2.Auth.Utils.Business.Converters.ExpressionConverter
  7. {
  8. public interface ILuExpressionParamReplaceVisitorOptions
  9. {
  10. IDictionary<ParameterExpression, Expression> Parameters { get; }
  11. }
  12. public class LuExpressionParamReplaceVisitor : ExpressionVisitor
  13. {
  14. public ILuExpressionParamReplaceVisitorOptions Options { get; }
  15. public LuExpressionParamReplaceVisitor(ILuExpressionParamReplaceVisitorOptions options)
  16. {
  17. Options = options;
  18. }
  19. protected override Expression VisitParameter(ParameterExpression node)
  20. {
  21. if (!Options.Parameters.ContainsKey(node))
  22. {
  23. LuResult<Expression>.Error(LuStatus.InternalError.ToInt(),
  24. $"Could not find a conversion for parameter {node}").Throw();
  25. }
  26. return Options.Parameters[node];
  27. }
  28. }
  29. }