Skip to content

Commit

Permalink
v3.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed Jun 24, 2023
1 parent 3fbca8b commit 5bbbd8a
Show file tree
Hide file tree
Showing 27 changed files with 219 additions and 111 deletions.
86 changes: 0 additions & 86 deletions lib/YANLib/Demo/YANHttpClient.cs

This file was deleted.

42 changes: 42 additions & 0 deletions lib/YANLib/Nullable/YANBool.Nullable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace YANLib.Nullable;

public static partial class YANBool
{
public static bool? ToBool<T>(this T? num) where T : struct
{
try
{
return Convert.ToBoolean(num);
}
catch
{
return default;
}
}

public static IEnumerable<bool?> ToBool<T>(this IEnumerable<T?> nums) where T : struct
{
if (nums is null || !nums.Any())
{
yield break;
}
foreach (var num in nums)
{
yield return num.ToBool();
}
}

public static bool? ToBool<T>(this string str, T? dfltVal) where T : struct => dfltVal.HasValue ? str.ToBool(dfltVal.Value) : default;

public static IEnumerable<bool?> ToBool<T>(this IEnumerable<string> strs, T? dfltVal) where T : struct
{
if (strs is null || !strs.Any())
{
yield break;
}
foreach (var num in strs)
{
yield return num.ToBool(dfltVal);
}
}
}
56 changes: 56 additions & 0 deletions lib/YANLib/Nullable/YANBool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace YANLib.Nullable;

public static partial class YANBool
{
public static bool? ToBool<T>(this T num) where T : struct
{
try
{
return Convert.ToBoolean(num);
}
catch
{
return default;
}
}

public static IEnumerable<bool?> ToBool<T>(this IEnumerable<T> nums) where T : struct
{
if (nums is null || !nums.Any())
{
yield break;
}
foreach (var num in nums)
{
yield return num.ToBool();
}
}

public static bool? ToBool(this string str) => bool.TryParse(str, out var num) && num;

public static IEnumerable<bool?> ToBool(this IEnumerable<string> strs)
{
if (strs is null || !strs.Any())
{
yield break;
}
foreach (var num in strs)
{
yield return num.ToBool();
}
}

public static bool? ToBool<T>(this string str, T dfltVal) where T : struct => bool.TryParse(str, out var num) ? num : dfltVal.ToBool();

public static IEnumerable<bool?> ToBool<T>(this IEnumerable<string> strs, T dfltVal) where T : struct
{
if (strs is null || !strs.Any())
{
yield break;
}
foreach (var num in strs)
{
yield return num.ToBool(dfltVal);
}
}
}
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Decimal.Nullable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static decimal? ToDecimal<T>(this T? num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Decimal.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static decimal? ToDecimal<T>(this T num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Double.Nullable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static double? ToDouble<T>(this T? num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Double.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static double? ToDouble<T>(this T num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Float.Nullable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static float? ToFloat<T>(this T? num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Float.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static float? ToFloat<T>(this T num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Int.Nullable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static int? ToInt<T>(this T? num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Int.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static int? ToInt<T>(this T num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Long.Nullable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static long? ToLong<T>(this T? num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Long.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static long? ToLong<T>(this T num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Nint.Nullable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static nint? ToNint<T>(this T? num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Sbyte.Nullable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static sbyte? ToSbyte<T>(this T? num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Sbyte.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static sbyte? ToSbyte<T>(this T num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Short.Nullable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static short? ToShort<T>(this T? num) where T : struct
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANNum.Short.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YANLib.Nullable;

public partial class YANNum
public static partial class YANNum
{

public static short? ToShort<T>(this T num) where T : struct
Expand Down
46 changes: 46 additions & 0 deletions lib/YANLib/YANBool.Nullable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using static System.Linq.Enumerable;

namespace YANLib;

public static partial class YANBool
{
public static bool ToBool<T>(this T? num) where T : struct
{
try
{
return Convert.ToBoolean(num);
}
catch
{
return default;
}
}

public static IEnumerable<bool> ToBool<T>(this IEnumerable<T?> nums) where T : struct
{
if (nums is null || !nums.Any())
{
yield break;
}
foreach (var num in nums)
{
yield return num.ToBool();
}
}

public static bool ToBool<T>(this string str, T? dfltVal) where T : struct => dfltVal.HasValue && str.ToBool(dfltVal.Value);

public static IEnumerable<bool> ToBool<T>(this IEnumerable<string> strs, T? dfltVal) where T : struct
{
if (strs is null || !strs.Any())
{
yield break;
}
foreach (var num in strs)
{
yield return num.ToBool(dfltVal);
}
}

public static IEnumerable<bool> GenerateRandomBools<T>(T? size) where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomBool());
}
Loading

0 comments on commit 5bbbd8a

Please sign in to comment.