public string Resolve(MemberInfo info)
            {
                if (info == null)
                {
                    return(null);
                }

                var name = info.Name;

                IPropertyMapping propertyMapping = null;

                if (this._settings.PropertyMappings.TryGetValue(info, out propertyMapping))
                {
                    return(propertyMapping.Name);
                }

                var att = ElasticsearchPropertyAttributeBase.From(info);

                if (att != null && !string.IsNullOrEmpty(att.Name))
                {
                    return(att.Name);
                }

                return(_settings.Serializer?.CreatePropertyMapping(info)?.Name ?? _settings.DefaultFieldNameInferrer(name));
            }
Пример #2
0
        /// <summary> Renames/Ignores a property based on the connection settings mapping or custom attributes for the property </summary>
        private void ApplyPropertyOverrides(MemberInfo member, JsonProperty property)
        {
            if (!this.ConnectionSettings.PropertyMappings.TryGetValue(member, out var propertyMapping))
            {
                propertyMapping = ElasticsearchPropertyAttributeBase.From(member);
            }

            var serializerMapping = this.ConnectionSettings.PropertyMappingProvider?.CreatePropertyMapping(member);

            var nameOverride = propertyMapping?.Name ?? serializerMapping?.Name;

            if (!string.IsNullOrWhiteSpace(nameOverride))
            {
                property.PropertyName = nameOverride;
            }

            var overrideIgnore = propertyMapping?.Ignore ?? serializerMapping?.Ignore;

            if (overrideIgnore.HasValue)
            {
                property.Ignored = overrideIgnore.Value;
            }
        }