private string ResolveMemberInfo(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 = ElasticsearchPropertyAttribute.From(info); if (att != null && !att.Name.IsNullOrEmpty()) { return(att.Name); } return(_settings.Serializer?.CreatePropertyName(info) ?? _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; } var propertyName = this.ConnectionSettings.Serializer?.CreatePropertyName(member); if (!propertyName.IsNullOrEmpty()) { property.PropertyName = propertyName; } return(property); } if (!propertyMapping.Name.IsNullOrEmpty()) { property.PropertyName = propertyMapping.Name; } property.Ignored = propertyMapping.Ignore; return(property); }
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)); }
public IProperties GetProperties(ConcurrentDictionary <Type, int> seenTypes = null, int maxRecursion = 0) { var properties = new Properties(); int seen; if (seenTypes != null && seenTypes.TryGetValue(_type, out seen) && seen > maxRecursion) { return(properties); } foreach (var propertyInfo in _type.GetProperties()) { var attribute = ElasticsearchPropertyAttribute.From(propertyInfo); if (attribute != null && attribute.Ignore) { continue; } var property = GetProperty(propertyInfo, attribute); properties.Add(propertyInfo, property); } return(properties); }