Ejemplo n.º 1
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);
        }
Ejemplo n.º 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 = ElasticAttributes.Type(type);

            if (att != null && !att.Name.IsNullOrEmpty())
            {
                typeName = att.Name;
            }
            else
            {
                typeName = _connectionSettings.DefaultTypeNameInferrer(type);
            }
            return(typeName);
        }
        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);
        }