private IProperty GetProperty(PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { var property = _visitor.Visit(propertyInfo, attribute); if (property != null) return property; if (propertyInfo.GetGetMethod().IsStatic) return null; if (attribute != null) property = attribute; else property = InferProperty(propertyInfo.PropertyType); var objectProperty = property as IObjectProperty; if (objectProperty != null) { var type = GetUnderlyingType(propertyInfo.PropertyType); var seenTypes = new ConcurrentDictionary<Type, int>(_seenTypes); seenTypes.AddOrUpdate(type, 0, (t, i) => ++i); var walker = new PropertyWalker(type, _visitor, _maxRecursion, seenTypes); objectProperty.Properties = walker.GetProperties(seenTypes, _maxRecursion); } _visitor.Visit(property, propertyInfo, attribute); return property; }
public void Visit(IProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { var nestedType = type as INestedProperty; if (nestedType != null) Visit(nestedType, propertyInfo, attribute); var objectType = type as IObjectProperty; if (objectType != null) Visit(objectType, propertyInfo, attribute); var binaryType = type as IBinaryProperty; if (binaryType != null) Visit(binaryType, propertyInfo, attribute); var booleanType = type as IBooleanProperty; if (booleanType != null) Visit(booleanType, propertyInfo, attribute); var dateType = type as IDateProperty; if (dateType != null) Visit(dateType, propertyInfo, attribute); var numberType = type as INumberProperty; if (numberType != null) Visit(numberType, propertyInfo, attribute); var stringType = type as IStringProperty; if (stringType != null) Visit(stringType, propertyInfo, attribute); var attachmentType = type as IAttachmentProperty; if (attachmentType != null) Visit(attachmentType, propertyInfo, attribute); var geoShapeType = type as IGeoShapeProperty; if (geoShapeType != null) Visit(geoShapeType, propertyInfo, attribute); var geoPointType = type as IGeoPointProperty; if (geoPointType != null) Visit(geoPointType, propertyInfo, attribute); var completionType = type as ICompletionProperty; if (completionType != null) Visit(completionType, propertyInfo, attribute); var ipType = type as IIpProperty; if (ipType != null) Visit(ipType, propertyInfo, attribute); var murmurType = type as IMurmur3HashProperty; if (murmurType != null) Visit(murmurType, propertyInfo, attribute); var tokenCountType = type as ITokenCountProperty; if (tokenCountType != null) Visit(tokenCountType, propertyInfo, attribute); }
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)); }
private IProperty GetProperty(PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { var property = _visitor.Visit(propertyInfo, attribute); if (property != null) { return(property); } if (propertyInfo.GetGetMethod().IsStatic) { return(null); } if (attribute != null) { property = attribute; } else { property = InferProperty(propertyInfo.PropertyType); } var objectProperty = property as IObjectProperty; if (objectProperty != null) { var type = GetUnderlyingType(propertyInfo.PropertyType); var seenTypes = new ConcurrentDictionary <Type, int>(_seenTypes); seenTypes.AddOrUpdate(type, 0, (t, i) => ++ i); var walker = new PropertyWalker(type, _visitor, _maxRecursion, seenTypes); objectProperty.Properties = walker.GetProperties(seenTypes, _maxRecursion); } _visitor.Visit(property, propertyInfo, attribute); return(property); }
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); }
public virtual void Visit(IMurmur3HashProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { }
public virtual void Visit(ICompletionProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { }
public virtual IProperty Visit(PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) => null;
public virtual void Visit(IBooleanProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { }
public virtual IProperty Visit(PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) => null;
public virtual void Visit(ICompletionProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { }
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; }
public virtual void Visit(IGeoPointProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { }
public virtual void Visit(IBooleanProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { }
public virtual void Visit(IMurmur3HashProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { }
public void Visit(IProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { var nestedType = type as INestedProperty; if (nestedType != null) { Visit(nestedType, propertyInfo, attribute); } var objectType = type as IObjectProperty; if (objectType != null) { Visit(objectType, propertyInfo, attribute); } var binaryType = type as IBinaryProperty; if (binaryType != null) { Visit(binaryType, propertyInfo, attribute); } var booleanType = type as IBooleanProperty; if (booleanType != null) { Visit(booleanType, propertyInfo, attribute); } var dateType = type as IDateProperty; if (dateType != null) { Visit(dateType, propertyInfo, attribute); } var numberType = type as INumberProperty; if (numberType != null) { Visit(numberType, propertyInfo, attribute); } var stringType = type as IStringProperty; if (stringType != null) { Visit(stringType, propertyInfo, attribute); } var attachmentType = type as IAttachmentProperty; if (attachmentType != null) { Visit(attachmentType, propertyInfo, attribute); } var geoShapeType = type as IGeoShapeProperty; if (geoShapeType != null) { Visit(geoShapeType, propertyInfo, attribute); } var geoPointType = type as IGeoPointProperty; if (geoPointType != null) { Visit(geoPointType, propertyInfo, attribute); } var completionType = type as ICompletionProperty; if (completionType != null) { Visit(completionType, propertyInfo, attribute); } var ipType = type as IIpProperty; if (ipType != null) { Visit(ipType, propertyInfo, attribute); } var murmurType = type as IMurmur3HashProperty; if (murmurType != null) { Visit(murmurType, propertyInfo, attribute); } var tokenCountType = type as ITokenCountProperty; if (tokenCountType != null) { Visit(tokenCountType, propertyInfo, attribute); } }
public virtual void Visit(IGeoPointProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttribute attribute) { }