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 string CleanHtml(this string html) | |
| { | |
| if (string.IsNullOrWhiteSpace(html)) | |
| return html; | |
| var buffer = new char[html.Length]; | |
| var output = buffer.AsSpan(); | |
| var inTag = false; | |
| var 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
| internal sealed class EntityComparer<TSource, TDestination> | |
| { | |
| private readonly TSource source; | |
| private readonly TDestination destination; | |
| public EntityComparer( | |
| TSource source, | |
| TDestination destination) | |
| { | |
| this.source = source; |
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 ThrowHelper | |
| { | |
| /// <summary> | |
| /// Throws <see cref="ArgumentNullException" /> if value is null. | |
| /// </summary> | |
| /// <exception cref="ArgumentNullException"></exception> | |
| public static void ThrowIfNull<T>(Expression<Func<T>> propertyExpression) | |
| { | |
| if (propertyExpression.Compile().Invoke() is not null) | |
| { |
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 JsonExtensions | |
| { | |
| private static readonly JsonSerializer JsonSerializer = JsonSerializer.CreateDefault(); | |
| /// <summary> | |
| /// Serializes the specified instance and writes the JSON structure | |
| /// </summary> | |
| /// <param name="value">The value of <typeparam name="T"></typeparam> to serialize.</param> | |
| /// <typeparam name="T">The type of the object to serialize.</typeparam> | |
| public static string ToJson<T>(this T 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 override int SaveChanges(bool acceptAllChangesOnSuccess) | |
| { | |
| OnBeforeSaving(); | |
| return base.SaveChanges(acceptAllChangesOnSuccess); | |
| } | |
| public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, | |
| CancellationToken cancellationToken = new CancellationToken()) | |
| { | |
| OnBeforeSaving(); |
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> | |
| /// Apply filter for hide soft deleted entities which implement the <see cref="ISoftDeletable" /> | |
| /// </summary> | |
| /// <param name="modelBuilder"><see cref="ModelBuilder" /></param> | |
| public static void ApplySoftDeleteFilter(this ModelBuilder modelBuilder) | |
| { | |
| bool IsSoftDeletable(ITypeBase t) => | |
| t != null && t.HasClrType() && typeof(ISoftDeletable).IsAssignableFrom(t.ClrType); | |
| var softDeletableTypes = modelBuilder.Model.GetEntityTypes() |
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 void ApplyConfigurationsFromAssembly(this ModelBuilder modelBuilder, Assembly assembly) | |
| { | |
| var interfaceType = typeof(IEntityTypeConfiguration<>); | |
| var methodApplyConfiguration = typeof(ModelBuilder) | |
| .GetMethods() | |
| .SingleOrDefault(i => i.IsGenericMethod | |
| && i.Name == nameof(ModelBuilder.ApplyConfiguration) | |
| && i.GetParameters().Any(p => p.ParameterType.Name == interfaceType.Name)); |
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; | |
| using System.IO; | |
| using System.IO.MemoryMappedFiles; | |
| using System.Runtime.Serialization.Formatters.Binary; | |
| public static class ReadWriteMemoryMappedFile | |
| { | |
| // allocated memory for this memory mapped file (bytes) | |
| private const int MMF_MAX_SIZE = byte.MaxValue; |
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
| var ftpRequest = (FtpWebRequest) WebRequest.Create($"{host}/{path}"); | |
| ftpRequest.Credentials = new NetworkCredential(username, password); | |
| /* When in doubt, use these options */ | |
| ftpRequest.UseBinary = true; | |
| ftpRequest.UsePassive = true; | |
| ftpRequest.KeepAlive = true; | |
| /* Specify the Type of FTP Request */ | |
| ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile; |
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; | |
| using System.Runtime.InteropServices; | |
| using System.Threading; | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| handler = new ConsoleEventDelegate(ConsoleEventCallback); | |
| SetConsoleCtrlHandler(handler, true); |
NewerOlder