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

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