-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #813 from polyadic/try
Add more Try* API wrappers
- Loading branch information
Showing
5 changed files
with
43 additions
and
2 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
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,14 @@ | ||
#if JSON_SERIALIZER_OPTIONS_TRY_GET_TYPE_INFO | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization.Metadata; | ||
|
||
namespace Funcky.Extensions; | ||
|
||
public static class JsonSerializerOptionsExtensions | ||
{ | ||
public static Option<JsonTypeInfo> GetTypeInfoOrNone(this JsonSerializerOptions options, Type type) | ||
=> options.TryGetTypeInfo(type, out var typeInfo) | ||
? typeInfo | ||
: Option<JsonTypeInfo>.None; | ||
} | ||
#endif |
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,18 @@ | ||
#if ORDERED_DICTIONARY | ||
using static Funcky.Internal.ValueMapper; | ||
|
||
namespace Funcky.Extensions; | ||
|
||
public static class OrderedDictionaryExtensions | ||
{ | ||
/// <summary>Determines the index of a specific key in the <see cref="System.Collections.Generic.OrderedDictionary{TKey,TValue}" />.</summary> | ||
/// <param name="dictionary">The dictionary to search.</param> | ||
/// <param name="key">The key to locate.</param> | ||
/// <exception cref="T:System.ArgumentNullException"> | ||
/// <paramref name="key" /> is <see langword="null" />.</exception> | ||
/// <returns>The index of <paramref name="key" /> if found; otherwise, <see cref="Option{TItem}.None"/>.</returns> | ||
public static Option<int> IndexOfOrNone<TKey, TValue>(this OrderedDictionary<TKey, TValue> dictionary, TKey key) | ||
where TKey : notnull | ||
=> MapNotFoundToNone(dictionary.IndexOf(key)); | ||
} | ||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
#nullable enable | ||
Funcky.Extensions.JsonSerializerOptionsExtensions | ||
Funcky.Extensions.OrderedDictionaryExtensions | ||
static Funcky.Extensions.JsonSerializerOptionsExtensions.GetTypeInfoOrNone(this System.Text.Json.JsonSerializerOptions! options, System.Type! type) -> Funcky.Monads.Option<System.Text.Json.Serialization.Metadata.JsonTypeInfo!> | ||
static Funcky.Extensions.OrderedDictionaryExtensions.IndexOfOrNone<TKey, TValue>(this System.Collections.Generic.OrderedDictionary<TKey, TValue>! dictionary, TKey key) -> Funcky.Monads.Option<int> | ||
static Funcky.Extensions.ParseExtensions.ParseIPNetworkOrNone(this string? candidate) -> Funcky.Monads.Option<System.Net.IPNetwork> | ||
static Funcky.Extensions.ParseExtensions.ParseIPNetworkOrNone(this System.ReadOnlySpan<char> candidate) -> Funcky.Monads.Option<System.Net.IPNetwork> |