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)); } var att = ElasticAttributes.Property(member, this.ConnectionSettings); if (att == null) { return(property); } if (!att.Name.IsNullOrEmpty()) { property.PropertyName = att.Name; } property.Ignored = att.OptOut; return(property); }
public string Resolve(MemberInfo info) { if (info == null) { return(null); } var name = info.Name; var resolvedName = name.ToCamelCase(); var att = ElasticAttributes.Property(info); if (att != null && !att.Name.IsNullOrEmpty()) { resolvedName = att.Name; } return(resolvedName); }
public string Resolve(MemberInfo info) { if (info == null) { return(null); } var name = info.Name; var att = ElasticAttributes.Property(info, _settings); if (att != null && !att.Name.IsNullOrEmpty()) { return(att.Name); } return(_settings.DefaultPropertyNameInferrer(name)); }
protected override Expression VisitMemberAccess(MemberExpression expression, Stack <string> stack, Stack <IElasticPropertyAttribute> properties) { if (stack != null) { var name = expression.Member.Name; var resolvedName = this._settings.DefaultPropertyNameInferrer(name); var att = ElasticAttributes.Property(expression.Member); if (att != null) { properties.Push(att); } if (att != null && !att.Name.IsNullOrEmpty()) { resolvedName = att.Name; } stack.Push(resolvedName); } return(base.VisitMemberAccess(expression, stack, properties)); }