Skip to content

Commit

Permalink
Merge pull request #53 from Tynab/develop
Browse files Browse the repository at this point in the history
v3.2.1
  • Loading branch information
Tynab authored Dec 3, 2023
2 parents 62db281 + 8e95bf5 commit 481e041
Show file tree
Hide file tree
Showing 41 changed files with 413 additions and 1,646 deletions.
9 changes: 9 additions & 0 deletions YANLib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "console", "console", "{8C44
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YANLib.Benchmarks", "console\YANLib.Benchmarks\YANLib.Benchmarks.csproj", "{241584E4-5815-4627-AE1D-D638644D4FDF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{495944F0-A2C2-4CD9-8462-E84C3BD041B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YANLib.Test", "test\YANLib.Test\YANLib.Test.csproj", "{2CED63D8-2023-4183-96BA-3512449D2F4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -95,6 +99,10 @@ Global
{241584E4-5815-4627-AE1D-D638644D4FDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{241584E4-5815-4627-AE1D-D638644D4FDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{241584E4-5815-4627-AE1D-D638644D4FDF}.Release|Any CPU.Build.0 = Release|Any CPU
{2CED63D8-2023-4183-96BA-3512449D2F4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CED63D8-2023-4183-96BA-3512449D2F4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CED63D8-2023-4183-96BA-3512449D2F4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CED63D8-2023-4183-96BA-3512449D2F4C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -112,6 +120,7 @@ Global
{2B031F5C-93EC-4222-93F4-4505B29CAB81} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0}
{DE74000F-A442-4A12-990F-C806C75BCA62} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0}
{241584E4-5815-4627-AE1D-D638644D4FDF} = {8C44E9D9-768E-4EB5-B305-40061382363E}
{2CED63D8-2023-4183-96BA-3512449D2F4C} = {495944F0-A2C2-4CD9-8462-E84C3BD041B4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F}
Expand Down
48 changes: 0 additions & 48 deletions lib/YANLib/YANBool.Nullable.cs

This file was deleted.

49 changes: 4 additions & 45 deletions lib/YANLib/YANBool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,21 @@ namespace YANLib;

public static partial class YANBool
{
public static bool ToBool<T>(this T num) where T : struct
public static bool ToBool(this object? num, object? dfltVal = null)
{
try
{
return Convert.ToBoolean(num);
}
catch
{
return default;
return dfltVal is not null && dfltVal.ToBool();
}
}

public static IEnumerable<bool> ToBool<T>(this IEnumerable<T> nums) where T : struct
{
if (nums.IsEmptyOrNull())
{
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.IsEmptyOrNull())
{
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.IsEmptyOrNull())
{
yield break;
}

foreach (var num in strs)
{
yield return num.ToBool(dfltVal);
}
}
public static IEnumerable<bool>? ToBool(this IEnumerable<object?> nums, object? dfltVal = null) => nums.IsEmptyOrNull() ? default : nums.Select(n => n.ToBool(dfltVal));

public static bool GenerateRandomBool() => GenerateRandomByte(0, 2) is 1;

public static IEnumerable<bool> GenerateRandomBools<T>(T size) where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomBool());
public static IEnumerable<bool> GenerateRandomBools(object? size = null) => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomBool());
}
33 changes: 19 additions & 14 deletions lib/YANLib/YANLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,28 @@
<PackAsTool>False</PackAsTool>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>Add:
- Enum

Update
- Text: check null attribute
- Json:
- byte[]
- Deserialize
- Deserializes
- StandardDeserialize
- StandardDeserializes
- CamelSerialize -&gt; StandardSerialize
- CamelSerializes -&gt; StandardSerializes</PackageReleaseNotes>
<PackageReleaseNotes>Update
- Bool
- Model
- Num
- Decimal
- Double
- Float
- Int
- Long
- Nint
- Nuint
- Sbyte
- Short
- Uint
- Ulong
- Ushort
- Pass
- Random</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageId>Tynab.YANLib</PackageId>
<Version>3.2.0</Version>
<Version>3.2.1</Version>
<LangVersion>preview</LangVersion>
</PropertyGroup>

Expand Down
1 change: 0 additions & 1 deletion lib/YANLib/YANModel.Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace YANLib;

public static partial class YANModel
{

public static bool AllPropertiesNotDefault<T>(this T? mdl)
{
if (mdl is null)
Expand Down
45 changes: 0 additions & 45 deletions lib/YANLib/YANNum.Byte.Nullable.cs

This file was deleted.

26 changes: 7 additions & 19 deletions lib/YANLib/YANNum.Byte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,27 @@ namespace YANLib;
public static partial class YANNum
{

public static byte ToByte<T>(this T num) where T : struct
public static byte ToByte(this object? num, object? dfltVal = null)
{
try
{
return Convert.ToByte(num);
}
catch
{
return default;
return dfltVal is null ? default : dfltVal.ToByte();
}
}

public static IEnumerable<byte>? ToByte<T>(this IEnumerable<T> nums) where T : struct => nums.IsEmptyOrNull() ? default : nums.Select(n => n.ToByte());
public static IEnumerable<byte>? ToByte(this IEnumerable<object?> nums, object? dfltVal = null) => nums.IsEmptyOrNull() ? default : nums.Select(n => n.ToByte(dfltVal));

public static byte ToByte(this string str) => byte.TryParse(str, out var num) ? num : default;

public static IEnumerable<byte>? ToByte(this IEnumerable<string> strs) => strs.IsEmptyOrNull() ? default : strs.Select(s => s.ToByte());

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

public static IEnumerable<byte>? ToByte<T>(this IEnumerable<string> strs, T dfltVal) where T : struct => strs.IsEmptyOrNull() ? default : strs.Select(s => s.ToByte(dfltVal));

public static byte GenerateRandomByte<T1, T2>(T1 min, T2 max) where T1 : struct where T2 : struct
public static byte GenerateRandomByte(object? min = null, object? max = null)
{
var minValue = min.ToByte();
var maxValue = max.ToByte();
var minValue = min is null ? byte.MinValue : min.ToByte();
var maxValue = max is null ? byte.MaxValue : max.ToByte();

return minValue > maxValue ? default : new Random().Next(minValue, maxValue).ToByte();
}

public static IEnumerable<byte> GenerateRandomBytes<T1, T2, T>(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomByte(min, max));

public static byte GenerateRandomByte() => GenerateRandomByte(byte.MinValue, byte.MaxValue);

public static byte GenerateRandomByte<T>(T max) where T : struct => GenerateRandomByte(byte.MinValue, max);
public static IEnumerable<byte> GenerateRandomBytes(object? min = null, object? max = null, object? size = null) => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomByte(min, max));
}
45 changes: 0 additions & 45 deletions lib/YANLib/YANNum.Decimal.Nullable.cs

This file was deleted.

29 changes: 5 additions & 24 deletions lib/YANLib/YANNum.Decimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,21 @@ namespace YANLib;

public static partial class YANNum
{

public static decimal ToDecimal<T>(this T num) where T : struct
public static decimal ToDecimal(this object? num, object? dfltVal = null)
{
try
{
return Convert.ToDecimal(num);
}
catch
{
return default;
return dfltVal is null ? default : dfltVal.ToDecimal();
}
}

public static IEnumerable<decimal>? ToDecimal<T>(this IEnumerable<T> nums) where T : struct => nums.IsEmptyOrNull() ? default : nums.Select(n => n.ToDecimal());

public static decimal ToDecimal(this string str) => decimal.TryParse(str, out var num) ? num : default;

public static IEnumerable<decimal>? ToDecimal(this IEnumerable<string> strs) => strs.IsEmptyOrNull() ? default : strs.Select(s => s.ToDecimal());

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

public static IEnumerable<decimal>? ToDecimal<T>(this IEnumerable<string> strs, T dfltVal) where T : struct => strs.IsEmptyOrNull() ? default : strs.Select(s => s.ToDecimal(dfltVal));

public static decimal GenerateRandomDecimal<T1, T2>(T1 min, T2 max) where T1 : struct where T2 : struct
{
var minValue = min.ToDecimal();
var maxValue = max.ToDecimal();

return minValue > maxValue ? default : new Random().NextDecimal(minValue, maxValue);
}

public static IEnumerable<decimal> GenerateRandomDecimals<T1, T2, T>(T1 min, T2 max, T size) where T1 : struct where T2 : struct where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomDecimal(min, max));
public static IEnumerable<decimal>? ToDecimal(this IEnumerable<object?> nums, object? dfltVal = null) => nums.IsEmptyOrNull() ? default : nums.Select(n => n.ToDecimal(dfltVal));

public static decimal GenerateRandomDecimal() => GenerateRandomDecimal(decimal.MinValue, decimal.MaxValue);
public static decimal GenerateRandomDecimal(object? min = null, object? max = null) => new Random().NextDecimal(min, max);

public static decimal GenerateRandomDecimal<T>(T max) where T : struct => GenerateRandomDecimal(decimal.MinValue, max);
public static IEnumerable<decimal> GenerateRandomDecimals(object? min = null, object? max = null, object? size = null) => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomDecimal(min, max));
}
Loading

0 comments on commit 481e041

Please sign in to comment.