-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
IParsable<T>
for url parameters
- Loading branch information
Showing
29 changed files
with
985 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.400", | ||
"version": "9.0.100", | ||
"rollForward": "latestFeature", | ||
"allowPrerelease": false | ||
}, | ||
"version": "8.8.0-alpha.1", | ||
"doc_current": "main", | ||
"doc_branch": "main" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Elastic.Clients.Elasticsearch/_Shared/Core/EnumValueParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace Elastic.Clients.Elasticsearch; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
|
||
internal static class EnumValueParser<T> | ||
where T : struct, Enum | ||
{ | ||
private static readonly Dictionary<string, T> ValueMap = new(StringComparer.OrdinalIgnoreCase); | ||
|
||
static EnumValueParser() | ||
{ | ||
foreach (var value in Enum.GetValues<T>()) | ||
{ | ||
var name = value.ToString(); | ||
ValueMap[name] = value; | ||
|
||
var field = typeof(T).GetField(name); | ||
var attribute = (EnumMemberAttribute?)Attribute.GetCustomAttribute(field!, typeof(EnumMemberAttribute)); | ||
if (attribute?.Value is not null) | ||
{ | ||
ValueMap[attribute.Value] = value; | ||
} | ||
} | ||
} | ||
|
||
public static bool TryParse(string input, out T result) | ||
{ | ||
return ValueMap.TryGetValue(input, out result); | ||
} | ||
|
||
public static T Parse(string input) | ||
{ | ||
if (ValueMap.TryGetValue(input, out var result)) | ||
{ | ||
return result; | ||
} | ||
|
||
throw new ArgumentException($"Unknown member '{input}' for enum '{typeof(T).Name}'."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
src/Elastic.Clients.Elasticsearch/_Shared/Core/Fluent/Fluent.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.