Add project files.

This commit is contained in:
2023-04-29 09:17:17 +03:00
commit 62178f1f32
493 changed files with 45863 additions and 0 deletions
@@ -0,0 +1,14 @@
namespace MyOffice.Core.Extensions;
public static class BoolExtensions
{
public static string ToLowerCase(this bool value)
{
return value.ToString().ToLower();
}
public static string? ToLowerCase(this bool? value)
{
return value == null ? null : value.ToString()?.ToLower();
}
}
@@ -0,0 +1,31 @@
namespace MyOffice.Core.Extensions;
using System.Security.Claims;
public static class ClaimsExtensions
{
public static string? GetValue(this IEnumerable<Claim> claims, string type)
{
return claims.FirstOrDefault(x => x.Type.Equals(type, StringComparison.OrdinalIgnoreCase))?.Value;
}
public static string? GetValue(this IEnumerable<Claim> claims, string[] types)
{
return claims.FirstOrDefault(x => types.Any(z => x.Type.Equals(z, StringComparison.OrdinalIgnoreCase)))?.Value;
}
public static string? GetEmail(this IEnumerable<Claim> claims)
{
return GetValue(claims, new[] { ClaimTypes.Email, "email" });
}
public static string? GetNameIdentifier(this IEnumerable<Claim> claims)
{
return GetValue(claims, ClaimTypes.NameIdentifier);
}
public static string? GetSID(this IEnumerable<Claim> claims)
{
return GetValue(claims, "sid");
}
}
@@ -0,0 +1,9 @@
namespace MyOffice.Core.Extensions;
public static class GuidExtensions
{
public static bool EqualsString(this Guid guid, string str)
{
return guid.ToString().EqualsIgnoreCase(str);
}
}
@@ -0,0 +1,29 @@
namespace MyOffice.Core.Extensions;
public static class StringExtensions
{
public static bool IsMissing(this string? str)
{
return str == null || string.IsNullOrEmpty(str) || string.IsNullOrEmpty(str.Trim());
}
public static bool IsPresent(this string? str)
{
return !IsMissing(str);
}
public static string? NullIfEmpty(this string? str)
{
return IsMissing(str) ? null : str;
}
public static bool EqualsIgnoreCase(this string? str, string? value)
{
return str != null && str.Equals(value, StringComparison.OrdinalIgnoreCase);
}
public static bool AsBool(this string? str, bool defaultValue = false)
{
return true.ToString().Equals(str, StringComparison.OrdinalIgnoreCase) || defaultValue;
}
}