public string GetTypeNameFor(Type type) { if (type == null) { return(null); } string typeName; if (_connectionSettings.DefaultTypeNames.TryGetValue(type, out typeName)) { return(typeName); } var att = ElasticAttributes.Type(type); if (att != null && !att.Name.IsNullOrEmpty()) { typeName = att.Name; } else { typeName = _connectionSettings.DefaultTypeNameInferrer(type); } return(typeName); }
public string Resolve(MemberInfo info) { if (info == null) { return(null); } var name = info.Name; var resolvedName = _settings.DefaultPropertyNameInferrer(name); var att = ElasticAttributes.Property(info); if (att != null && !att.Name.IsNullOrEmpty()) { resolvedName = att.Name; } return(resolvedName); }
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)); }
private PropertyInfo GetInferredId(Type type) { // if the type specifies through ElasticAttribute what the id prop is // use that no matter what var esTypeAtt = ElasticAttributes.Type(type); if (esTypeAtt != null && !string.IsNullOrWhiteSpace(esTypeAtt.IdProperty)) { return(GetPropertyCaseInsensitive(type, esTypeAtt.IdProperty)); } var propertyName = "Id"; //Try Id on its own case insensitive var idProperty = GetPropertyCaseInsensitive(type, propertyName); if (idProperty != null) { return(idProperty); } //Try TypeNameId case insensitive idProperty = GetPropertyCaseInsensitive(type, type.Name + propertyName); if (idProperty != null) { return(idProperty); } //Try TypeName_Id case insensitive idProperty = GetPropertyCaseInsensitive(type, type.Name + "_" + propertyName); if (idProperty != null) { return(idProperty); } return(idProperty); }