Skip to content

Instantly share code, notes, and snippets.

View Calabonga's full-sized avatar
💭
Пишите правильный код

Sergei Calabonga Calabonga

💭
Пишите правильный код
View GitHub Profile
@Calabonga
Calabonga / SomeProjectFile.csproj
Created August 16, 2024 00:17
Copy DLLs after Visual Studio Build
<Target Name="CopyDLLs" AfterTargets="Build">
<Message Text="Executing Copy Command Task" Importance="High" />
<PropertyGroup>
<PublishedCommandsDir>..\..\..\..\Calabonga.Commandex.Shell\PublishedCommands</PublishedCommandsDir>
</PropertyGroup>
<Copy SourceFiles="$(TargetDir)$(ProjectName).dll;$(TargetDir)$(ProjectName).pdb" DestinationFolder="$(PublishedCommandsDir)" />
<Message Text="Command $(ProjectName) successfully copied" Importance="High" />
</Target>
@Calabonga
Calabonga / Money.cs
Created March 11, 2024 03:04
Implicit operators demo
public struct Money
{
private readonly double _amount;
public Money(double amount)
{
_amount = amount;
}
public double Amount => _amount;
@Calabonga
Calabonga / BenchmarkTemplate.cs
Created December 22, 2022 01:01
Benchmarking with BenchmarkDotNet
[RankColumn]
[HideColumns(new string[] { "Job" })]
[MemoryDiagnoser(false)]
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net70)]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByMethod)]
public class Benchmark
{
// ... start from here
}
@Calabonga
Calabonga / JsonSerializerOptions Demo
Created September 3, 2022 03:44
JsonSerializerOptions
var options = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
}
var json = JsonSerializer.Serialize(state, options);
@Calabonga
Calabonga / AppSettings.cs
Last active January 20, 2025 09:09
Console Application Template
namespace Samples;
public class AppSettings
{
public string? Name { get; set; }
}
@Calabonga
Calabonga / Directory.Build.props
Created May 4, 2022 01:39
Visual Studio properties for all projects
<Project>
<PropertyGroup>
<!-- <LangVersion>latest</LangVersion> -->
<!--<LangVersion>preview</LangVersion>-->
<LangVersion>8</LangVersion>
</PropertyGroup>
</Project>
@Calabonga
Calabonga / xunit.runner.json
Last active April 29, 2022 03:21
xunit.runner.json
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method",
"methodDisplayOptions": "all"
}
@Calabonga
Calabonga / TaskHelper.cs
Created April 20, 2022 08:24
Run and forget task C#
public static class TaskHelper
{
/// <summary>
/// Runs a TPL Task fire-and-forget style, the right way - in the
/// background, separate from the current thread, with no risk
/// of it trying to rejoin the current thread.
/// </summary>
public static void RunBg(Func<Task> fn) => Task.Run(fn).ConfigureAwait(false);
/// <summary>
@Calabonga
Calabonga / AsyncHelper.cs
Last active April 20, 2022 04:17
AsyncHelper helps to start asynchronous method as synchronously
public static class AsyncHelpers
{
/// <summary>
/// Executes an async Task<T> method which has a void return value synchronously
/// </summary>
/// <param name="task">Task<T> method to execute</param>
public static void RunSync(Func<Task> task)
{
var oldContext = SynchronizationContext.Current;
var synch = new ExclusiveSynchronizationContext();

Layered Architecture

flowchart TD
    subgraph FEATURES
        Presentation --> Application
        Application --> Domain
        Domain --> Infrastructure
        Infrastructure --> Database
 end