Beispiel #1
0
        private string ResolveType(Type type)
        {
            if (type == null)
            {
                return(null);
            }

            string typeName;

            if (_relationNames.TryGetValue(type, out typeName))
            {
                return(typeName);
            }

            if (_connectionSettings.DefaultRelationNames.TryGetValue(type, out typeName))
            {
                _relationNames.TryAdd(type, typeName);
                return(typeName);
            }

            var att = ElasticsearchTypeAttribute.From(type);

            if (att != null && !att.RelationName.IsNullOrEmpty())
            {
                typeName = att.RelationName;
            }
            else
            {
                typeName = type.Name.ToLowerInvariant();
            }

            _relationNames.TryAdd(type, typeName);
            return(typeName);
        }
Beispiel #2
0
        public string GetTypeNameFor(Type type)
        {
            if (type == null)
            {
                return(null);
            }
            string typeName;

            if (_connectionSettings.DefaultTypeNames.TryGetValue(type, out typeName))
            {
                return(typeName);
            }

            var att = ElasticsearchTypeAttribute.From(type);

            if (att != null && !att.Name.IsNullOrEmpty())
            {
                typeName = att.Name;
            }
            else
            {
                typeName = _connectionSettings.DefaultTypeNameInferrer(type);
            }
            return(typeName);
        }
Beispiel #3
0
        private string ResolveType(Type type)
        {
            if (type == null)
            {
                return(null);
            }
            string typeName;

            if (TypeNames.TryGetValue(type, out typeName))
            {
                return(typeName);
            }

            if (_connectionSettings.DefaultTypeNames.TryGetValue(type, out typeName))
            {
                TypeNames.TryAdd(type, typeName);
                return(typeName);
            }

            var att = ElasticsearchTypeAttribute.From(type);

            if (att != null && !att.Name.IsNullOrEmpty())
            {
                typeName = att.Name;
            }
            else
            {
                typeName = _connectionSettings.DefaultTypeNameInferrer(type);
            }

            TypeNames.TryAdd(type, typeName);
            return(typeName);
        }
Beispiel #4
0
        private PropertyInfo GetInferredId(Type type)
        {
            // if the type specifies through ElasticAttribute what the id prop is
            // use that no matter what

            this._connectionSettings.IdProperties.TryGetValue(type, out var propertyName);
            if (!propertyName.IsNullOrEmpty())
            {
                return(GetPropertyCaseInsensitive(type, propertyName));
            }

            var esTypeAtt = ElasticsearchTypeAttribute.From(type);

            propertyName = (esTypeAtt?.IdProperty.IsNullOrEmpty() ?? true) ? "Id" : esTypeAtt?.IdProperty;

            return(GetPropertyCaseInsensitive(type, propertyName));
        }
        private string ResolveType(Type type)
        {
            if (type == null)
            {
                return(null);
            }

            if (_typeNames.TryGetValue(type, out var typeName))
            {
                return(typeName);
            }

            if (_connectionSettings.DefaultTypeNames.TryGetValue(type, out typeName))
            {
                _typeNames.TryAdd(type, typeName);
                return(typeName);
            }

            var att = ElasticsearchTypeAttribute.From(type);

            if (att != null && !att.Name.IsNullOrEmpty())
            {
                typeName = att.Name;
            }
            else
            {
                var dataContract = type.GetAttributes <DataContractAttribute>().FirstOrDefault();
                if (dataContract != null)
                {
                    typeName = dataContract.Name;
                }
                else
                {
                    var inferredType = _connectionSettings.DefaultTypeNameInferrer(type);
                    typeName = !inferredType.IsNullOrEmpty() ? inferredType : _connectionSettings.DefaultTypeName;
                }
            }
            if (typeName.IsNullOrEmpty())
            {
                throw new ArgumentNullException($"{type.FullName} resolved to an empty string or null");
            }

            _typeNames.TryAdd(type, typeName);
            return(typeName);
        }