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.Name.IsNullOrEmpty()) { typeName = att.Name; } else { typeName = _connectionSettings.DefaultTypeNameInferrer(type); } RelationNames.TryAdd(type, typeName); 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?.Name != 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); }