Skip to content

Commit f451a9f

Browse files
stevejgordongithub-actions[bot]
authored andcommitted
Add TryGet methods for internally tagged unions (#6916)
1 parent 5de3e6f commit f451a9f

File tree

7 files changed

+84
-13
lines changed

7 files changed

+84
-13
lines changed

src/Elastic.Clients.Elasticsearch/Types/Mapping/Properties.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Diagnostics.CodeAnalysis;
76
using System.Linq.Expressions;
87
using System.Text.Json;
98
using System.Text.Json.Serialization;
@@ -20,18 +19,6 @@ public partial class Properties
2019

2120
public void Add<TDocument>(Expression<Func<TDocument, object>> propertyName, IProperty property) => BackingDictionary.Add(Sanitize(propertyName), property);
2221

23-
public bool TryGetProperty<T>(PropertyName propertyName, [NotNullWhen(returnValue: true)] out T? property) where T : class, IProperty
24-
{
25-
if (BackingDictionary.TryGetValue(propertyName, out var matchedProperty) && matchedProperty is T finalProperty)
26-
{
27-
property = finalProperty;
28-
return true;
29-
}
30-
31-
property = null;
32-
return false;
33-
}
34-
3522
protected override PropertyName Sanitize(PropertyName key) => _settings?.Inferrer.PropertyName(key) ?? key;
3623
}
3724

src/Elastic.Clients.Elasticsearch/_Generated/Types/Analysis/Analyzers.g.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Elastic.Transport;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Linq.Expressions;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
@@ -37,6 +38,19 @@ public Analyzers(IDictionary<string, IAnalyzer> container) : base(container)
3738
}
3839

3940
public void Add(string name, IAnalyzer analyzer) => BackingDictionary.Add(Sanitize(name), analyzer);
41+
public bool TryGetAnalyzer(string name, [NotNullWhen(returnValue: true)] out IAnalyzer analyzer) => BackingDictionary.TryGetValue(name, out analyzer);
42+
public bool TryGetAnalyzer<T>(string name, [NotNullWhen(returnValue: true)] out T? analyzer)
43+
where T : class, IAnalyzer
44+
{
45+
if (BackingDictionary.TryGetValue(name, out var matchedValue) && matchedValue is T finalValue)
46+
{
47+
analyzer = finalValue;
48+
return true;
49+
}
50+
51+
analyzer = null;
52+
return false;
53+
}
4054
}
4155

4256
public sealed partial class AnalyzersDescriptor : IsADictionaryDescriptor<AnalyzersDescriptor, Analyzers, string, IAnalyzer>

src/Elastic.Clients.Elasticsearch/_Generated/Types/Analysis/CharFilterDefinitions.g.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Elastic.Transport;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Linq.Expressions;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
@@ -37,6 +38,19 @@ public CharFilterDefinitions(IDictionary<string, ICharFilterDefinition> containe
3738
}
3839

3940
public void Add(string name, ICharFilterDefinition charFilterDefinition) => BackingDictionary.Add(Sanitize(name), charFilterDefinition);
41+
public bool TryGetCharFilterDefinition(string name, [NotNullWhen(returnValue: true)] out ICharFilterDefinition charFilterDefinition) => BackingDictionary.TryGetValue(name, out charFilterDefinition);
42+
public bool TryGetCharFilterDefinition<T>(string name, [NotNullWhen(returnValue: true)] out T? charFilterDefinition)
43+
where T : class, ICharFilterDefinition
44+
{
45+
if (BackingDictionary.TryGetValue(name, out var matchedValue) && matchedValue is T finalValue)
46+
{
47+
charFilterDefinition = finalValue;
48+
return true;
49+
}
50+
51+
charFilterDefinition = null;
52+
return false;
53+
}
4054
}
4155

4256
public sealed partial class CharFilterDefinitionsDescriptor : IsADictionaryDescriptor<CharFilterDefinitionsDescriptor, CharFilterDefinitions, string, ICharFilterDefinition>

src/Elastic.Clients.Elasticsearch/_Generated/Types/Analysis/Normalizers.g.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Elastic.Transport;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Linq.Expressions;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
@@ -37,6 +38,19 @@ public Normalizers(IDictionary<string, INormalizer> container) : base(container)
3738
}
3839

3940
public void Add(string name, INormalizer normalizer) => BackingDictionary.Add(Sanitize(name), normalizer);
41+
public bool TryGetNormalizer(string name, [NotNullWhen(returnValue: true)] out INormalizer normalizer) => BackingDictionary.TryGetValue(name, out normalizer);
42+
public bool TryGetNormalizer<T>(string name, [NotNullWhen(returnValue: true)] out T? normalizer)
43+
where T : class, INormalizer
44+
{
45+
if (BackingDictionary.TryGetValue(name, out var matchedValue) && matchedValue is T finalValue)
46+
{
47+
normalizer = finalValue;
48+
return true;
49+
}
50+
51+
normalizer = null;
52+
return false;
53+
}
4054
}
4155

4256
public sealed partial class NormalizersDescriptor : IsADictionaryDescriptor<NormalizersDescriptor, Normalizers, string, INormalizer>

src/Elastic.Clients.Elasticsearch/_Generated/Types/Analysis/TokenFilterDefinitions.g.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Elastic.Transport;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Linq.Expressions;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
@@ -37,6 +38,19 @@ public TokenFilterDefinitions(IDictionary<string, ITokenFilterDefinition> contai
3738
}
3839

3940
public void Add(string name, ITokenFilterDefinition tokenFilterDefinition) => BackingDictionary.Add(Sanitize(name), tokenFilterDefinition);
41+
public bool TryGetTokenFilterDefinition(string name, [NotNullWhen(returnValue: true)] out ITokenFilterDefinition tokenFilterDefinition) => BackingDictionary.TryGetValue(name, out tokenFilterDefinition);
42+
public bool TryGetTokenFilterDefinition<T>(string name, [NotNullWhen(returnValue: true)] out T? tokenFilterDefinition)
43+
where T : class, ITokenFilterDefinition
44+
{
45+
if (BackingDictionary.TryGetValue(name, out var matchedValue) && matchedValue is T finalValue)
46+
{
47+
tokenFilterDefinition = finalValue;
48+
return true;
49+
}
50+
51+
tokenFilterDefinition = null;
52+
return false;
53+
}
4054
}
4155

4256
public sealed partial class TokenFilterDefinitionsDescriptor : IsADictionaryDescriptor<TokenFilterDefinitionsDescriptor, TokenFilterDefinitions, string, ITokenFilterDefinition>

src/Elastic.Clients.Elasticsearch/_Generated/Types/Analysis/TokenizerDefinitions.g.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Elastic.Transport;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Linq.Expressions;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
@@ -37,6 +38,19 @@ public TokenizerDefinitions(IDictionary<string, ITokenizerDefinition> container)
3738
}
3839

3940
public void Add(string name, ITokenizerDefinition tokenizerDefinition) => BackingDictionary.Add(Sanitize(name), tokenizerDefinition);
41+
public bool TryGetTokenizerDefinition(string name, [NotNullWhen(returnValue: true)] out ITokenizerDefinition tokenizerDefinition) => BackingDictionary.TryGetValue(name, out tokenizerDefinition);
42+
public bool TryGetTokenizerDefinition<T>(string name, [NotNullWhen(returnValue: true)] out T? tokenizerDefinition)
43+
where T : class, ITokenizerDefinition
44+
{
45+
if (BackingDictionary.TryGetValue(name, out var matchedValue) && matchedValue is T finalValue)
46+
{
47+
tokenizerDefinition = finalValue;
48+
return true;
49+
}
50+
51+
tokenizerDefinition = null;
52+
return false;
53+
}
4054
}
4155

4256
public sealed partial class TokenizerDefinitionsDescriptor : IsADictionaryDescriptor<TokenizerDefinitionsDescriptor, TokenizerDefinitions, string, ITokenizerDefinition>

src/Elastic.Clients.Elasticsearch/_Generated/Types/Mapping/Properties.g.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Elastic.Transport;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Linq.Expressions;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
@@ -37,6 +38,19 @@ public Properties(IDictionary<PropertyName, IProperty> container) : base(contain
3738
}
3839

3940
public void Add(PropertyName propertyName, IProperty property) => BackingDictionary.Add(Sanitize(propertyName), property);
41+
public bool TryGetProperty(PropertyName propertyName, [NotNullWhen(returnValue: true)] out IProperty property) => BackingDictionary.TryGetValue(propertyName, out property);
42+
public bool TryGetProperty<T>(PropertyName propertyName, [NotNullWhen(returnValue: true)] out T? property)
43+
where T : class, IProperty
44+
{
45+
if (BackingDictionary.TryGetValue(propertyName, out var matchedValue) && matchedValue is T finalValue)
46+
{
47+
property = finalValue;
48+
return true;
49+
}
50+
51+
property = null;
52+
return false;
53+
}
4054
}
4155

4256
public sealed partial class PropertiesDescriptor<TDocument> : IsADictionaryDescriptor<PropertiesDescriptor<TDocument>, Properties, PropertyName, IProperty>

0 commit comments

Comments
 (0)