/// <summary> /// Translate an expression tree into a compiled OData query. /// </summary> /// <param name="expression">The expression tree to translate</param> /// <param name="contractResolver">The contract resolvers to use to determine property names from members used with expressions.</param> /// <returns>An OData <see cref="QueryNode"/></returns> internal static QueryNode Compile(Expression expression, DatasyncContractResolver contractResolver) { var visitor = new FilterBuildingExpressionVisitor(contractResolver); visitor.Visit(expression); return(visitor.FilterExpression.FirstOrDefault()); }
/// <summary> /// Gets the table member name referenced by an expression, or return null. /// </summary> /// <param name="expression">The expression to check</param> /// <param name="contractResolver">The contract resolvers to use to determine property names from members used with expressions.</param> /// <returns>the table member name</returns> internal static string GetTableMemberName(Expression expression, DatasyncContractResolver contractResolver) { Arguments.IsNotNull(expression, nameof(expression)); Arguments.IsNotNull(contractResolver, nameof(contractResolver)); if (expression is MemberExpression member && member.Expression.NodeType == ExpressionType.Parameter) { JsonProperty property = contractResolver.ResolveProperty(member.Member); return(property.PropertyName); } return(null); }
public DatasyncSerializerSettings_Tests() { settings = new(); contractResolver = settings.ContractResolver; }
/// <summary> /// Initializes a new instance of the <see cref="FilterBuildingExpressionVisitor"/> /// </summary> /// <param name="contractResolver">The contract resolvers to use to determine property names from members used with expressions.</param> internal FilterBuildingExpressionVisitor(DatasyncContractResolver contractResolver) : base() { Arguments.IsNotNull(contractResolver, nameof(contractResolver)); ContractResolver = contractResolver; }