Example #1
0
        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);
        }
Example #2
0
        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);
        }