public PropertyInfo IdInfo(Type type) { ElasticTypeAttribute elasticTypeAttribute = ElasticAttributes.Type(type); if (elasticTypeAttribute != null && !string.IsNullOrWhiteSpace(elasticTypeAttribute.IdProperty)) { return(this.GetPropertyCaseInsensitive(type, elasticTypeAttribute.IdProperty)); } const string propertyName = "Id"; PropertyInfo propertyCaseInsensitive1 = this.GetPropertyCaseInsensitive(type, propertyName); if (propertyCaseInsensitive1 != (PropertyInfo)null) { return(propertyCaseInsensitive1); } PropertyInfo propertyCaseInsensitive2 = this.GetPropertyCaseInsensitive(type, type.Name + propertyName); if (propertyCaseInsensitive2 != (PropertyInfo)null) { return(propertyCaseInsensitive2); } PropertyInfo propertyCaseInsensitive3 = this.GetPropertyCaseInsensitive(type, type.Name + "_" + propertyName); if (propertyCaseInsensitive3 != (PropertyInfo)null) { return(propertyCaseInsensitive3); } else { return(propertyCaseInsensitive3); } }
internal void WriteProperties(JsonWriter jsonWriter) { var properties = this._type.GetProperties(); foreach (var p in properties) { var att = ElasticAttributes.Property(p); if (att != null && att.OptOut) { continue; } var propertyName = this.Infer.PropertyName(p); var type = GetElasticSearchType(att, p); if (type == null) //could not get type from attribute or infer from CLR type. { continue; } jsonWriter.WritePropertyName(propertyName); jsonWriter.WriteStartObject(); { if (att == null) //properties that follow can not be inferred from the CLR. { jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue(type); //jsonWriter.WriteEnd(); } if (att != null) { this.WritePropertiesFromAttribute(jsonWriter, att, propertyName, type); } if (type == "object" || type == "nested") { var deepType = p.PropertyType; var deepTypeName = this.Infer.TypeName(deepType); var seenTypes = new ConcurrentDictionary <Type, int>(this.SeenTypes); seenTypes.AddOrUpdate(deepType, 0, (t, i) => ++ i); var newTypeMappingWriter = new TypeMappingWriter(deepType, deepTypeName, this._connectionSettings, MaxRecursion, seenTypes); var nestedProperties = newTypeMappingWriter.MapPropertiesFromAttributes(); jsonWriter.WritePropertyName("properties"); nestedProperties.WriteTo(jsonWriter); } } jsonWriter.WriteEnd(); } }