diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/Extensions/Extensions.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/Extensions/Extensions.cs index 52e3a14c5d1..81210225106 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/Extensions/Extensions.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/Extensions/Extensions.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Runtime.ExceptionServices; @@ -172,13 +173,14 @@ internal static bool HasAny(this IEnumerable list, Func predicate internal static bool HasAny(this IEnumerable list) => list != null && list.Any(); - internal static bool IsEmpty(this IEnumerable list) + internal static bool IsNullOrEmpty(this IEnumerable? list) { - if (list == null) + if (list is null) return true; var enumerable = list as T[] ?? list.ToArray(); - return !enumerable.Any() || enumerable.All(t => t == null); + + return (enumerable.Length == 0) || enumerable.All(x => x is null); } internal static void ThrowIfNull(this T value, string name, string message = null) @@ -189,9 +191,9 @@ internal static void ThrowIfNull(this T value, string name, string message = throw new ArgumentNullException(name, "Argument can not be null when " + message); } - internal static bool IsNullOrEmpty(this string value) => string.IsNullOrWhiteSpace(value); + internal static bool IsNullOrEmpty(this string? value) => string.IsNullOrWhiteSpace(value); - internal static bool IsNullOrEmptyCommaSeparatedList(this string value, out string[] split) + internal static bool IsNullOrEmptyCommaSeparatedList(this string? value, [NotNullWhen(false)] out string[]? split) { split = null; if (string.IsNullOrWhiteSpace(value)) diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Field/Field.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Field/Field.cs index 3075cbc7219..6ecff34ef00 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Field/Field.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Field/Field.cs @@ -4,24 +4,29 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq.Expressions; using System.Reflection; using System.Text.Json.Serialization; + using Elastic.Transport; #if ELASTICSEARCH_SERVERLESS namespace Elastic.Clients.Elasticsearch.Serverless; #else + namespace Elastic.Clients.Elasticsearch; #endif [JsonConverter(typeof(FieldConverter))] -[DebuggerDisplay("{" + nameof(DebugDisplay) + ",nq}")] -public sealed class Field : IEquatable, IUrlParameter +[DebuggerDisplay($"{nameof(DebuggerDisplay)},nq")] +public sealed class Field : + IEquatable, + IUrlParameter { private readonly object _comparisonValue; - private readonly Type _type; + private readonly Type? _type; // Pseudo and metadata fields @@ -30,143 +35,173 @@ public sealed class Field : IEquatable, IUrlParameter public static Field KeyField = new("_key"); public static Field CountField = new("_count"); - public Field(string name) : this(name, null, null) { } + /// + /// The name of the field + /// + public string? Name { get; } + + /// + /// An expression from which the name of the field can be inferred + /// + public Expression? Expression { get; } + + /// + /// A property from which the name of the field can be inferred + /// + public PropertyInfo? Property { get; } + + /// + /// A boost to apply to the field + /// + public double? Boost { get; set; } + + /// + /// A format to apply to the field. + /// + /// + /// Can be used only for Doc Value Fields Elasticsearch 6.4.0+ + /// + public string? Format { get; set; } + + internal bool CachableExpression { get; } + + #region Constructors + + public Field(string name) : this(name, null, null) + { + } - public Field(string name, double boost) : this(name, boost, null) { } + public Field(string name, double boost) : this(name, boost, null) + { + } - public Field(string name, string format) : this(name, null, format) { } + public Field(string name, string format) : this(name, null, format) + { + } public Field(string name, double? boost, string? format) { - name.ThrowIfNullOrEmpty(nameof(name)); + if (string.IsNullOrEmpty(name)) + throw new ArgumentException($"{name} can not be null or empty.", nameof(name)); + Name = ParseFieldName(name, out var b); Boost = b ?? boost; Format = format; + _comparisonValue = Name; } - public Field(Expression expression, double? boost = null, string format = null) + public Field(Expression expression, double? boost = null, string? format = null) { Expression = expression ?? throw new ArgumentNullException(nameof(expression)); Boost = boost; Format = format; + _comparisonValue = expression.ComparisonValueFromExpression(out var type, out var cachable); _type = type; + CachableExpression = cachable; } - public Field(PropertyInfo property, double? boost = null, string format = null) + public Field(PropertyInfo property, double? boost = null, string? format = null) { Property = property ?? throw new ArgumentNullException(nameof(property)); Boost = boost; Format = format; + _comparisonValue = property; _type = property.DeclaringType; } - /// - /// A boost to apply to the field - /// - public double? Boost { get; set; } + #endregion Constructors - /// - /// A format to apply to the field. - /// - /// - /// Can be used only for Doc Value Fields Elasticsearch 6.4.0+ - /// - public string? Format { get; set; } + #region Factory Methods - internal bool CachableExpression { get; } + public static Field? FromString(string? name) => string.IsNullOrEmpty(name) ? null : new Field(name); - /// - /// An expression from which the name of the field can be inferred - /// - public Expression Expression { get; } + public static Field? FromExpression(Expression? expression) => expression is null ? null : new Field(expression); - /// - /// The name of the field - /// - public string Name { get; } + public static Field? FromProperty(PropertyInfo? property) => property is null ? null : new Field(property); - /// - /// A property from which the name of the field can be inferred - /// - public PropertyInfo Property { get; } + #endregion Factory Methods - internal string DebugDisplay => - $"{Expression?.ToString() ?? PropertyDebug ?? Name}{(Boost.HasValue ? "^" + Boost.Value : string.Empty)}" - + $"{(!string.IsNullOrEmpty(Format) ? " format: " + Format : string.Empty)}" - + $"{(_type == null ? string.Empty : " typeof: " + _type.Name)}"; + #region Conversion Operators - private string PropertyDebug => Property == null ? null : $"PropertyInfo: {Property.Name}"; + public static implicit operator Field?(string? name) => FromString(name); - public bool Equals(Field other) => _type != null - ? other != null && _type == other._type && _comparisonValue.Equals(other._comparisonValue) - : other != null && _comparisonValue.Equals(other._comparisonValue); + public static implicit operator Field?(Expression? expression) => FromExpression(expression); - string IUrlParameter.GetString(ITransportConfiguration settings) + public static implicit operator Field?(PropertyInfo? property) => FromProperty(property); + + #endregion Conversion Operators + + #region Combinator Methods + + public Fields And(Field field) { - if (settings is not IElasticsearchClientSettings elasticsearchSettings) - { - throw new ArgumentNullException(nameof(settings), - $"Can not resolve {nameof(Field)} if no {nameof(IElasticsearchClientSettings)} is provided"); - } + if (field is null) + throw new ArgumentNullException(nameof(field)); - return GetStringCore(elasticsearchSettings); + return new([this, field]); } - private string GetStringCore(IElasticsearchClientSettings settings) + public Fields And(Expression> expression, double? boost = null, string? format = null) { - if (settings is null) - { - throw new ArgumentNullException(nameof(settings), - $"Can not resolve {nameof(Field)} if no {nameof(IElasticsearchClientSettings)} is provided"); - } + if (expression is null) + throw new ArgumentNullException(nameof(expression)); - return settings.Inferrer.Field(this); + return new([this, new Field(expression, boost, format)]); } - public override string ToString() => DebugDisplay; + public Fields And(Expression> expression, double? boost = null, string? format = null) + { + if (expression is null) + throw new ArgumentNullException(nameof(expression)); - public Fields And(Field field) => new(new[] { this, field }); + return new([this, new Field(expression, boost, format)]); + } - public Fields And(Expression> field, double? boost = null, string format = null) - where T : class => - new(new[] { this, new Field(field, boost, format) }); + public Fields And(string field, double? boost = null, string? format = null) + { + if (field is null) + throw new ArgumentNullException(nameof(field)); - public Fields And(Expression> field, double? boost = null, string format = null) - where T : class => - new(new[] { this, new Field(field, boost, format) }); + return new([this, new Field(field, boost, format)]); + } - public Fields And(string field, double? boost = null, string format = null) => - new(new[] { this, new Field(field, boost, format) }); + public Fields And(PropertyInfo property, double? boost = null, string? format = null) + { + if (property is null) + throw new ArgumentNullException(nameof(property)); - public Fields And(PropertyInfo property, double? boost = null, string format = null) => - new(new[] { this, new Field(property, boost, format) }); + return new([this, new Field(property, boost, format)]); + } - private static string ParseFieldName(string name, out double? boost) - { - boost = null; - if (name == null) - return null; + #endregion Combinator Methods - var caretIndex = name.IndexOf('^'); - if (caretIndex == -1) - return name; + #region Equality - var parts = name.Split(new[] { '^' }, 2, StringSplitOptions.RemoveEmptyEntries); - name = parts[0]; - boost = double.Parse(parts[1], CultureInfo.InvariantCulture); - return name; - } + public static bool operator ==(Field? a, Field? b) => Equals(a, b); - public static implicit operator Field(string name) => name.IsNullOrEmpty() ? null : new Field(name); + public static bool operator !=(Field? a, Field? b) => !Equals(a, b); - public static implicit operator Field(Expression expression) => - expression == null ? null : new Field(expression); + public bool Equals(Field? other) => + other switch + { + not null when _type is not null => (_type == other._type) && _comparisonValue.Equals(other._comparisonValue), + not null when _type is null => _comparisonValue.Equals(other._comparisonValue), + _ => false + }; - public static implicit operator Field(PropertyInfo property) => property == null ? null : new Field(property); + public override bool Equals(object? obj) => + obj switch + { + Field f => Equals(f), + string s => Equals(s), + Expression e => Equals(e), + PropertyInfo p => Equals(p), + _ => false + }; public override int GetHashCode() { @@ -178,22 +213,50 @@ public override int GetHashCode() } } - public override bool Equals(object obj) + #endregion Equality + + #region IUrlParameter + + string IUrlParameter.GetString(ITransportConfiguration settings) { - switch (obj) + if (settings is not IElasticsearchClientSettings elasticsearchSettings) { - case string s: - return Equals(s); - case PropertyInfo p: - return Equals(p); - case Field f: - return Equals(f); - default: - return false; + throw new ArgumentNullException(nameof(settings), + $"Can not resolve {nameof(Field)} if no {nameof(IElasticsearchClientSettings)} is provided"); } + + return elasticsearchSettings.Inferrer.Field(this); } - public static bool operator ==(Field x, Field y) => Equals(x, y); + #endregion IUrlParameter + + #region Debugging + + public override string ToString() => + $"{Expression?.ToString() ?? PropertyDebug ?? Name}{(Boost.HasValue ? "^" + Boost.Value : string.Empty)}" + + $"{(!string.IsNullOrEmpty(Format) ? " format: " + Format : string.Empty)}" + + $"{(_type == null ? string.Empty : " typeof: " + _type.Name)}"; + + internal string DebuggerDisplay => ToString(); + + private string? PropertyDebug => Property is null ? null : $"PropertyInfo: {Property.Name}"; - public static bool operator !=(Field x, Field y) => !Equals(x, y); + #endregion Debugging + + [return: NotNullIfNotNull(nameof(name))] + private static string? ParseFieldName(string? name, out double? boost) + { + boost = null; + if (name is null) + return null; + + var caretIndex = name.IndexOf('^'); + if (caretIndex == -1) + return name; + + var parts = name.Split(new[] { '^' }, 2, StringSplitOptions.RemoveEmptyEntries); + name = parts[0]; + boost = double.Parse(parts[1], CultureInfo.InvariantCulture); + return name; + } } diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Fields/Fields.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Fields/Fields.cs index dec3a645ad7..0112a9e2f2b 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Fields/Fields.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Fields/Fields.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; -using System.Text.Json; + using Elastic.Transport; #if ELASTICSEARCH_SERVERLESS @@ -18,141 +18,209 @@ namespace Elastic.Clients.Elasticsearch.Serverless; namespace Elastic.Clients.Elasticsearch; #endif -[DebuggerDisplay("{DebugDisplay,nq}")] -public sealed class Fields : IUrlParameter, IEnumerable, IEquatable +[DebuggerDisplay($"{nameof(DebuggerDisplay)},nq")] +public sealed class Fields : + IEquatable, + IEnumerable, + IUrlParameter { internal readonly List ListOfFields; - internal Fields() => ListOfFields = new List(); + #region Constructors - internal Fields(IEnumerable fieldNames) => ListOfFields = new List(fieldNames); + internal Fields() => ListOfFields = []; - private string DebugDisplay => - $"Count: {ListOfFields.Count} [" + - string.Join(",", ListOfFields.Select((t, i) => $"({i + 1}: {t?.DebugDisplay ?? "NULL"})")) + "]"; + internal Fields(IEnumerable fields) + { + if (fields is null) + throw new ArgumentNullException(nameof(fields)); - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + ListOfFields = [.. fields.Where(f => f is not null)]; + } - public IEnumerator GetEnumerator() => ListOfFields.GetEnumerator(); + #endregion Constructors - public bool Equals(Fields other) => EqualsAllFields(ListOfFields, other?.ListOfFields); + #region Factory Methods - string IUrlParameter.GetString(ITransportConfiguration? settings) - { - if (settings is not IElasticsearchClientSettings elasticsearchClientSettings) - { - throw new ArgumentNullException(nameof(settings), - $"Can not resolve {nameof(Fields)} if no {nameof(IElasticsearchClientSettings)} is provided"); - } + public static Fields? FromField(Field? field) => field is null + ? null + : new Fields([field]); - return string.Join(",", - ListOfFields.Where(f => f != null).Select(f => ((IUrlParameter)f).GetString(elasticsearchClientSettings))); - } + public static Fields? FromFields(Field[]? fields) => fields.IsNullOrEmpty() + ? null + : new Fields(fields!); - public override string ToString() => DebugDisplay; + public static Fields? FromString(string? name) => name.IsNullOrEmptyCommaSeparatedList(out var split) + ? null + : new Fields(split.Select(f => new Field(f))); - public static implicit operator Fields(string[] fields) => - fields.IsEmpty() ? null : new Fields(fields.Select(f => new Field(f))); + public static Fields? FromStrings(string[]? names) => names.IsNullOrEmpty() + ? null + : new Fields(names!.Select(f => new Field(f))); - public static implicit operator Fields(string field) => field.IsNullOrEmptyCommaSeparatedList(out var split) + public static Fields? FromExpression(Expression? expression) => expression is null ? null - : new Fields(split.Select(f => new Field(f))); + : new Fields([new Field(expression)]); - public static implicit operator Fields(Expression[] fields) => - fields.IsEmpty() ? null : new Fields(fields.Select(f => new Field(f))); + public static Fields? FromExpressions(Expression[]? expressions) => expressions.IsNullOrEmpty() + ? null + : new Fields(expressions!.Select(f => new Field(f))); - public static implicit operator Fields(Expression field) => - field == null ? null : new Fields(new[] { new Field(field) }); + public static Fields? FromExpression(Expression>? expression) => expression is null + ? null + : new Fields([new Field(expression)]); - public static implicit operator Fields(Field field) => field == null ? null : new Fields(new[] { field }); + public static Fields? FromExpressions(Expression>[]? expressions) => expressions.IsNullOrEmpty() + ? null + : new Fields(expressions!.Select(f => new Field(f))); + + public static Fields? FromProperty(PropertyInfo? property) => property is null + ? null + : new Fields([property]); - public static implicit operator Fields(PropertyInfo field) => - field == null ? null : new Fields(new Field[] { field }); + public static Fields? FromProperties(PropertyInfo[]? properties) => properties.IsNullOrEmpty() + ? null + : new Fields(properties!.Select(f => new Field(f))); - public static implicit operator Fields(PropertyInfo[] fields) => - fields.IsEmpty() ? null : new Fields(fields.Select(f => new Field(f))); + #endregion Factory Methods - public static implicit operator Fields(Field[] fields) => fields.IsEmpty() ? null : new Fields(fields); + #region Conversion Operators - public Fields And(Expression> field, double? boost = null, string format = null) - where T : class - { - ListOfFields.Add(new Field(field, boost, format)); - return this; - } + public static implicit operator Fields?(Field? field) => FromField(field); + + public static implicit operator Fields?(Field[]? fields) => FromFields(fields); + + public static implicit operator Fields?(string? name) => FromString(name); + + public static implicit operator Fields?(string[]? names) => FromStrings(names); + + public static implicit operator Fields?(Expression? expression) => FromExpression(expression); + + public static implicit operator Fields?(Expression[]? expressions) => FromExpressions(expressions); + + public static implicit operator Fields?(PropertyInfo? property) => FromProperty(property); + + public static implicit operator Fields?(PropertyInfo[]? properties) => FromProperties(properties); + + #endregion Conversion Operators + + #region Combinator Methods - public Fields And(string field, double? boost = null, string format = null) + public Fields And(params Field?[] fields) { - ListOfFields.Add(new Field(field, boost, format)); + if (fields is null) + throw new ArgumentNullException(nameof(fields)); + + ListOfFields.AddRange(fields.Where(f => f is not null)); + return this; } - public Fields And(PropertyInfo property, double? boost = null) + public Fields And(params string?[] names) { - ListOfFields.Add(new Field(property, boost)); + if (names is null) + throw new ArgumentNullException(nameof(names)); + + ListOfFields.AddRange(names.Where(f => f is not null).Select(f => new Field(f))); + return this; } - public Fields And(params Expression>[] fields) where T : class + public Fields And(params Expression>?[] expressions) { - ListOfFields.AddRange(fields.Select(f => new Field(f))); + if (expressions is null) + throw new ArgumentNullException(nameof(expressions)); + + ListOfFields.AddRange(expressions.Where(f => f is not null).Select(f => new Field(f))); + return this; } - public Fields And(params string[] fields) + public Fields And(Expression> expression, double? boost = null, string? format = null) + where T : class { - ListOfFields.AddRange(fields.Select(f => new Field(f))); + if (expression is null) + throw new ArgumentNullException(nameof(expression)); + + ListOfFields.Add(new Field(expression, boost, format)); + return this; } - public Fields And(params PropertyInfo[] properties) + public Fields And(params PropertyInfo?[] properties) { - ListOfFields.AddRange(properties.Select(f => new Field(f))); + if (properties is null) + throw new ArgumentNullException(nameof(properties)); + + ListOfFields.AddRange(properties.Where(x => x is not null).Select(f => new Field(f))); + return this; } - public Fields And(params Field[] fields) + #endregion Combinator Methods + + #region Equality + + public static bool operator ==(Fields? left, Fields? right) => Equals(left, right); + + public static bool operator !=(Fields? left, Fields? right) => !Equals(left, right); + + public override bool Equals(object? obj) => + obj switch + { + Fields f => Equals(f), + Field[] f => Equals(f), + Field f => Equals(f), + string s => Equals(s), + string[] s => Equals(s), + Expression e => Equals(e), + Expression[] e => Equals(e), + PropertyInfo p => Equals(p), + PropertyInfo[] p => Equals(p), + _ => false + }; + + public override int GetHashCode() => ListOfFields.GetHashCode(); + + public bool Equals(Fields? other) => (ListOfFields, other?.ListOfFields) switch { - ListOfFields.AddRange(fields); - return this; - } + (null, null) => true, + ({ } a, { } b) => (a.Count == b.Count) && !a.Except(b).Any(), + _ => false + }; + + #endregion Equality + + #region IEnumerable + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public static bool operator ==(Fields left, Fields right) => Equals(left, right); + public IEnumerator GetEnumerator() => ListOfFields.GetEnumerator(); + + #endregion IEnumerable - public static bool operator !=(Fields left, Fields right) => !Equals(left, right); + #region IUrlParameter - public override bool Equals(object obj) + string IUrlParameter.GetString(ITransportConfiguration? settings) { - switch (obj) + if (settings is not IElasticsearchClientSettings elasticsearchClientSettings) { - case Fields f: - return Equals(f); - case string s: - return Equals(s); - case Field fn: - return Equals(fn); - case Field[] fns: - return Equals(fns); - case Expression e: - return Equals(e); - case Expression[] es: - return Equals(es); - default: - return false; + throw new ArgumentNullException(nameof(settings), + $"Can not resolve {nameof(Fields)} if no {nameof(IElasticsearchClientSettings)} is provided"); } - } - private static bool EqualsAllFields(IReadOnlyList thisTypes, IReadOnlyList otherTypes) - { - if (thisTypes == null && otherTypes == null) - return true; - if (thisTypes == null || otherTypes == null) - return false; - if (thisTypes.Count != otherTypes.Count) - return false; - - return thisTypes.Count == otherTypes.Count && !thisTypes.Except(otherTypes).Any(); + return string.Join(",", ListOfFields.Select(f => ((IUrlParameter)f).GetString(elasticsearchClientSettings))); } - public override int GetHashCode() => ListOfFields.GetHashCode(); + #endregion IUrlParameter + + #region Debugging + + public override string ToString() => + $"Count: {ListOfFields.Count} [" + + string.Join(",", ListOfFields.Select((t, i) => $"({i + 1}: {t?.DebuggerDisplay})")) + "]"; + + private string DebuggerDisplay => ToString(); + + #endregion Debugging } diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Id/Ids.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Id/Ids.cs index 7e2fe48daf0..9385d4a80a7 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Id/Ids.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Id/Ids.cs @@ -66,7 +66,7 @@ public static implicit operator Ids(string value) => value.IsNullOrEmptyCommaSeparatedList(out var arr) ? null : new Ids(arr); public static implicit operator Ids(string[] value) => - value.IsEmpty() ? null : new Ids(value); + value.IsNullOrEmpty() ? null : new Ids(value); public override bool Equals(object obj) => obj is Ids other && Equals(other); diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Indices/Indices.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Indices/Indices.cs index 86a96c56df5..2a23cba5062 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Indices/Indices.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/Indices/Indices.cs @@ -138,9 +138,9 @@ public static Indices Parse(string indicesString) public static implicit operator Indices(string indicesString) => Parse(indicesString); - public static implicit operator Indices(string[] indices) => indices.IsEmpty() ? null : new Indices(indices); + public static implicit operator Indices(string[] indices) => indices.IsNullOrEmpty() ? null : new Indices(indices); - public static implicit operator Indices(IndexName[] indices) => indices.IsEmpty() ? null : new Indices(indices); + public static implicit operator Indices(IndexName[] indices) => indices.IsNullOrEmpty() ? null : new Indices(indices); public static implicit operator Indices(IndexName index) => index == null ? null : new Indices(new[] { index }); diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/JoinFieldRouting/Routing.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/JoinFieldRouting/Routing.cs index 024545157a6..518c1420c64 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/JoinFieldRouting/Routing.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/Infer/JoinFieldRouting/Routing.cs @@ -94,7 +94,7 @@ public static implicit operator Routing(string routing) => routing.IsNullOrEmptyCommaSeparatedList(out _) ? null : new Routing(routing); public static implicit operator Routing(string[] routing) => - routing.IsEmpty() ? null : new Routing(string.Join(",", routing)); + routing.IsNullOrEmpty() ? null : new Routing(string.Join(",", routing)); public static implicit operator Routing(long routing) => new(routing); diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/DataStreamNames/DataStreamNames.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/DataStreamNames/DataStreamNames.cs index c7eb0bff77c..5c0bbfaf5b6 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/DataStreamNames/DataStreamNames.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/DataStreamNames/DataStreamNames.cs @@ -34,7 +34,7 @@ public sealed class DataStreamNames : IUrlParameter, IEnumerable public override string ToString() => string.Join(",", Names.Where(f => f is not null).Select(f => f.Name)); - public static implicit operator DataStreamNames(string[] dataStreamNames) => dataStreamNames.IsEmpty() ? null : new DataStreamNames(dataStreamNames.Select(f => new DataStreamName(f))); + public static implicit operator DataStreamNames(string[] dataStreamNames) => dataStreamNames.IsNullOrEmpty() ? null : new DataStreamNames(dataStreamNames.Select(f => new DataStreamName(f))); public static implicit operator DataStreamNames(string dataStreamName) => dataStreamName.IsNullOrEmptyCommaSeparatedList(out var split) ? null @@ -42,7 +42,7 @@ public static implicit operator DataStreamNames(string dataStreamName) => dataSt public static implicit operator DataStreamNames(DataStreamName dataStreamName) => dataStreamName == null ? null : new DataStreamNames(new[] { dataStreamName }); - public static implicit operator DataStreamNames(DataStreamName[] dataStreamNames) => dataStreamNames.IsEmpty() ? null : new DataStreamNames(dataStreamNames); + public static implicit operator DataStreamNames(DataStreamName[] dataStreamNames) => dataStreamNames.IsNullOrEmpty() ? null : new DataStreamNames(dataStreamNames); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/Name/Names.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/Name/Names.cs index a66545cbf07..19f7e64c788 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/Name/Names.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/Name/Names.cs @@ -43,7 +43,7 @@ string IUrlParameter.GetString(ITransportConfiguration? settings) => public static implicit operator Names(string names) => Parse(names); - public static implicit operator Names(string[] names) => names.IsEmpty() ? null : new Names(names); + public static implicit operator Names(string[] names) => names.IsNullOrEmpty() ? null : new Names(names); public static bool operator ==(Names left, Names right) => Equals(left, right); diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/NodeIds/NodeIds.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/NodeIds/NodeIds.cs index 91095fd814e..38f045d330e 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/NodeIds/NodeIds.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/NodeIds/NodeIds.cs @@ -38,7 +38,7 @@ public NodeIds(IEnumerable nodeIds) public static implicit operator NodeIds(string nodes) => Parse(nodes); - public static implicit operator NodeIds(string[] nodes) => nodes.IsEmpty() ? null : new NodeIds(nodes); + public static implicit operator NodeIds(string[] nodes) => nodes.IsNullOrEmpty() ? null : new NodeIds(nodes); public static bool operator ==(NodeIds left, NodeIds right) => Equals(left, right); diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/ScrollIds/ScrollIds.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/ScrollIds/ScrollIds.cs index 2beb5475f10..d261b36c264 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/ScrollIds/ScrollIds.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/UrlParameters/ScrollIds/ScrollIds.cs @@ -34,7 +34,7 @@ public sealed class ScrollIds : IUrlParameter, IEnumerable, IEquatable public override string ToString() => string.Join(",", Ids.Where(f => f is not null).Select(f => f.Id)); - public static implicit operator ScrollIds(string[] scrollIds) => scrollIds.IsEmpty() ? null : new ScrollIds(scrollIds.Select(f => new ScrollId(f))); + public static implicit operator ScrollIds(string[] scrollIds) => scrollIds.IsNullOrEmpty() ? null : new ScrollIds(scrollIds.Select(f => new ScrollId(f))); public static implicit operator ScrollIds(string scrollIds) => scrollIds.IsNullOrEmptyCommaSeparatedList(out var split) ? null @@ -42,7 +42,7 @@ public static implicit operator ScrollIds(string scrollIds) => scrollIds.IsNullO public static implicit operator ScrollIds(ScrollId scrollId) => scrollId == null ? null : new ScrollIds(new[] { scrollId }); - public static implicit operator ScrollIds(ScrollId[] scrollIds) => scrollIds.IsEmpty() ? null : new ScrollIds(scrollIds); + public static implicit operator ScrollIds(ScrollId[] scrollIds) => scrollIds.IsNullOrEmpty() ? null : new ScrollIds(scrollIds); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();