Exemplo n.º 1
0
        public FieldMapping GetMapping(Field field, bool followAlias = false)
        {
            if (_inferrer == null)
            {
                throw new InvalidOperationException("Unable to resolve Field without inferrer");
            }

            return(GetMapping(_inferrer.Field(field), followAlias));
        }
Exemplo n.º 2
0
    public override void Visit(IMatchQuery query)
    {
        var inferrer = new Inferrer(new ConnectionSettings(new InMemoryConnection()));

        Field = inferrer.Field(query.Field);
        Value = query.Query;
    }
Exemplo n.º 3
0
        private IProperties MergeProperties(IProperties codeProperties, IProperties serverProperties)
        {
            if (codeProperties == null && serverProperties == null)
            {
                return(null);
            }

            IProperties mergedCodeProperties = null;

            // resolve code mapping property expressions using inferrer
            if (codeProperties != null)
            {
                mergedCodeProperties = new Properties();

                foreach (var kvp in codeProperties)
                {
                    var propertyName = kvp.Key;
                    if (_inferrer != null && (String.IsNullOrEmpty(kvp.Key.Name) || kvp.Value is IFieldAliasProperty))
                    {
                        propertyName = _inferrer.PropertyName(kvp.Key) ?? kvp.Key;
                    }

                    mergedCodeProperties[propertyName] = kvp.Value;
                }

                if (_inferrer != null)
                {
                    // resolve field alias
                    foreach (var kvp in codeProperties)
                    {
                        if (!(kvp.Value is IFieldAliasProperty aliasProperty))
                        {
                            continue;
                        }

                        mergedCodeProperties[kvp.Key] = new FieldAliasProperty {
                            LocalMetadata = aliasProperty.LocalMetadata,
                            Path          = _inferrer?.Field(aliasProperty.Path) ?? aliasProperty.Path,
                            Name          = aliasProperty.Name
                        };
                    }
                }
            }

            // no need to merge
            if (mergedCodeProperties == null || serverProperties == null)
            {
                return(mergedCodeProperties ?? serverProperties);
            }

            IProperties properties = new Properties();

            foreach (var serverProperty in serverProperties)
            {
                var merged = serverProperty.Value;
                if (mergedCodeProperties.TryGetValue(serverProperty.Key, out var codeProperty))
                {
                    merged.LocalMetadata = codeProperty.LocalMetadata;
                }

                switch (merged)
                {
                case IObjectProperty objectProperty:
                    var codeObjectProperty = codeProperty as IObjectProperty;
                    objectProperty.Properties = MergeProperties(codeObjectProperty?.Properties, objectProperty.Properties);
                    break;

                case ITextProperty textProperty:
                    var codeTextProperty = codeProperty as ITextProperty;
                    textProperty.Fields = MergeProperties(codeTextProperty?.Fields, textProperty.Fields);
                    break;
                }

                properties.Add(serverProperty.Key, merged);
            }

            foreach (var codeProperty in mergedCodeProperties)
            {
                if (properties.TryGetValue(codeProperty.Key, out _))
                {
                    continue;
                }

                properties.Add(codeProperty.Key, codeProperty.Value);
            }

            return(properties);
        }
 protected string InferField(Expression <Func <T, object> > objectPath) => Infer.Field(objectPath);