示例#1
0
        public string Resolve(MemberInfo info)
        {
            if (info == null)
            {
                return(null);
            }

            var name = info.Name;

            var att = ElasticsearchPropertyAttribute.From(info);

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

            return(_settings.DefaultFieldNameInferrer(name));
        }
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var property = base.CreateProperty(member, memberSerialization);

            // Skip serialization of empty collections that has DefaultValueHandling set to Ignore.
            if (property.DefaultValueHandling.HasValue &&
                property.DefaultValueHandling.Value == DefaultValueHandling.Ignore &&
                !typeof(string).IsAssignableFrom(property.PropertyType) &&
                typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
            {
                Predicate <object> shouldSerialize = obj =>
                {
                    var collection = property.ValueProvider.GetValue(obj) as ICollection;
                    return(collection == null || collection.Count != 0);
                };
                property.ShouldSerialize = property.ShouldSerialize == null ? shouldSerialize : (o => property.ShouldSerialize(o) && shouldSerialize(o));
            }

            IPropertyMapping propertyMapping = null;

            if (!this.ConnectionSettings.PropertyMappings.TryGetValue(member, out propertyMapping))
            {
                propertyMapping = ElasticsearchPropertyAttribute.From(member);
            }

            if (propertyMapping == null)
            {
                var jsonIgnoreAttribute = member.GetCustomAttributes(typeof(JsonIgnoreAttribute), true);
                if (jsonIgnoreAttribute.HasAny())
                {
                    property.Ignored = true;
                }
                return(property);
            }

            if (!propertyMapping.Name.IsNullOrEmpty())
            {
                property.PropertyName = propertyMapping.Name;
            }
            property.Ignored = propertyMapping.Ignore;

            return(property);
        }
 public override IProperty Visit(PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) => new StringProperty();
 /** Similarily, override the Visit method on IBooleanProperty and set DocValues = false */
 public override void Visit(IBooleanProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute)
 {
     type.DocValues = false;
 }