🧗♂️
This file contains hidden or 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
| public static bool IsNullOrEmpty([NotNullWhen(false)] this string? str) => str?.Length is null or 0; | |
| public static bool IsNullOrEmpty([NotNullWhen(false)] this string? str) => str is null or { Length: 0 }; |
This file contains hidden or 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
| using Autofac; | |
| using Autofac.Extensions.DependencyInjection; | |
| using HanyCo.Infra; | |
| using Library.Cqrs; | |
| using Library.Mapping; | |
| namespace BlazorApp; |
This file contains hidden or 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
| public class Monad<TValue> | |
| { | |
| private readonly TValue? _value; | |
| public Monad(TValue? value) | |
| => this._value = value; | |
| public Monad<TResult?> AnyWay<TResult>(in Func<TValue?, TResult?> func) | |
| => new(func(this._value)); |
This file contains hidden or 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
| using System.Linq.Expressions; | |
| namespace Library.Data.Linq; | |
| //! Reference: http://www.albahari.com/nutshell/predicatebuilder.aspx | |
| public static class PredicateBuilder | |
| { | |
| public static Expression<Func<T, bool>> True<T>() => f => true; | |
| public static Expression<Func<T, bool>> False<T>() => f => false; |
This file contains hidden or 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
| /// <summary> | |
| /// Resize the image to the specified width and height. | |
| /// </summary> | |
| /// <param name="image">The image to resize.</param> | |
| /// <param name="width">The width to resize to.</param> | |
| /// <param name="height">The height to resize to.</param> | |
| /// <returns>The resized image.</returns> | |
| public static Bitmap ResizeImage(Image image, int width, int height) | |
| { | |
| //a holder for the result |
This file contains hidden or 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
| <Project> | |
| <PropertyGroup> | |
| <TargetFramework>net6.0</TargetFramework> | |
| <LangVersion>preview</LangVersion> | |
| <EnablePreviewFeatures>true</EnablePreviewFeatures> | |
| <GenerateRequiresPreviewFeaturesAttribute>true</GenerateRequiresPreviewFeaturesAttribute> | |
| <Nullable>enable</Nullable> | |
| <ImplicitUsings>enable</ImplicitUsings> | |
| </PropertyGroup> | |
| <PropertyGroup> |
This file contains hidden or 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
| public static class SystemHostsFileManager | |
| { | |
| private static readonly string _filePath = @"C:\Windows\System32\drivers\etc\hosts"; | |
| public static IEnumerable<(string Ip, string Site, string? Description)> ReadRules() => | |
| from rule in File.ReadAllText(_filePath).Split(Environment.NewLine) | |
| where !string.IsNullOrEmpty(rule) && !rule.StartsWith("#") | |
| let description = rule.IndexOf("#") > 0 ? rule[(rule.IndexOf("#") + 1)..] : null | |
| let pair = rule.Split(" ") | |
| let ip = pair[0].Trim() |
This file contains hidden or 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
| public static class XmlSerializer | |
| { | |
| public static void Serialize<T>(T? o, string path!!, bool indent = true) | |
| { | |
| var serializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); | |
| using var writer = new StreamWriter(path); | |
| using var xmlWriter = System.Xml.XmlWriter.Create(writer, new System.Xml.XmlWriterSettings { Indent = indent }); | |
| serializer.Serialize(xmlWriter, o); | |
| } |
This file contains hidden or 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
| puvlic static class Extensions | |
| { | |
| public static Func<TResult> Compose<TResult>(this Func<TResult> create!!, params Func<TResult, TResult>[] funcs!!) | |
| { | |
| var result = () => | |
| { | |
| var value = create(); | |
| foreach (var func in funcs) | |
| { | |
| value = func(value); |
This file contains hidden or 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
| public record PagingParams(in int PageIndex = 0, in int? PageSize = null); | |
| public record PagingResult<T>(IReadOnlyList<T> Result, in long TotalCount); | |
| public static async Task<PagingResult<T>> ToListPagingAsync<T>(this IQueryable<T> query, PagingParams? paging, CancellationToken cancellationToken = default) | |
| { | |
| var total = await query.CountAsync(cancellationToken: cancellationToken); | |
| if (paging is null or { PageSize: null or 0 }) | |
| { | |
| var dbNoPagingResult = await query.ToListAsync(cancellationToken: cancellationToken); |