private (Expression BodyExpression, Func <string, object> Converter) GetValueBodyExpression(ParameterExpression entityParameter, string pathToProperty) { if (string.IsNullOrWhiteSpace(pathToProperty)) { return(entityParameter, i => i); } var pathSegments = this.ParsePropertyPath(pathToProperty); // INavigationSelector navigationSelector = null; ISearchDescriptor objectDescriptor = this; Expression valueExpression = entityParameter; foreach (var pathSegment in pathSegments) { if (objectDescriptor.Navigations.TryGetValue(pathSegment, out var navigation)) { valueExpression = GetExpressionBodyReferencingValue(navigation.GetTargetExpression, valueExpression); // valueExpression = Expression.Invoke(navigation.GetTargetExpression, valueExpression); objectDescriptor = navigation.ObjectDescriptor; } else if (objectDescriptor.Fields.TryGetValue(pathSegment, out var field)) { return(GetExpressionBodyReferencingValue(field.GetValueExpression, valueExpression), field.ConvertFromString); // return (Expression.Invoke(field.GetValueExpression, valueExpression), field.ConvertFromString); } } var defaultField = objectDescriptor.DefaultValueProperty; return(GetExpressionBodyReferencingValue(defaultField.GetValueExpression, valueExpression), defaultField.ConvertFromString); // return (Expression.Invoke(defaultField.GetValueExpression, valueExpression), defaultField.ConvertFromString); }
private SearchMetadata GetStructure(string name, ISearchDescriptor descriptor) => new SearchMetadata( name, descriptor.Name, descriptor.Fields.Keys .Select(k => new SearchMetadata(k, descriptor.Name)) .Union(descriptor.Navigations.Select(v => GetStructure(v.Key, v.Value.ObjectDescriptor)) ).ToList());