Skip to content

Instantly share code, notes, and snippets.

View Zodt's full-sized avatar
🇷🇸

Roman Vorontsov Zodt

🇷🇸
  • Finstar LLC
  • Belgrade, Serbia
  • 02:01 (UTC +02:00)
  • X @R_3pV
View GitHub Profile
using System.Runtime.InteropServices;
using System.Collections.Concurrent;
using System.Diagnostics;
namespace Utilities.Common.Telemetry;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
/// <summary>
/// Provides extension methods for IServiceCollection to add an activity source factory.
@Zodt
Zodt / Description.md
Last active July 6, 2023 22:50
A basic representation of the implementation of the interceptor functionality in unit tests.

Based on the materials of YouTube video by Nick Chapsas (@Elfocrash)

How should it work?

InterceptionFromAttribute

This attribute indicates to the source code generator the type and its method in which certain methods specified in the Intercepted<TInterception, TReturn> arguments should be intercepted The source code generator can get the following data from this data:

  • Line numbers and the path to the file containing this type;
using System.Collections;
using System.Collections.Generic;
namespace DotNetDesignPatternDemos.Structural.Proxy
{
class Creature
{
public byte Age;
public int X, Y;
}
using System;
using System.Threading.Tasks;
namespace RetryPolicy
{
/// <summary>
/// A class that can execute a specific code block multiple times, using linear retries.
/// </summary>
internal class LinearRetryPolicy<TResult>
{
@Zodt
Zodt / 1.JsonTimeSpanConverter.cs
Last active March 17, 2023 07:19
TimeSpan converter for Swagger
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Core.Json.Converters
{
public class JsonTimeSpanConverter : JsonConverter<TimeSpan>
{
public bool WithoutSeconds { get; init; }
@Zodt
Zodt / README.md
Last active March 7, 2024 20:05
Получение бейджика Verified для GitHub коммитов

[WINDOWS] Получение бейджика Verified для GitHub коммитов

Это пошаговое руководство о том, как включить автоматическое подписание Git-коммитов с помощью GPG для всех приложений, которые не поддерживают его изначально (например: GitHub Desktop, JetBrains Rider, ...)

@Zodt
Zodt / 1.ExceptionExtensions.cs
Last active July 6, 2023 22:34
MediatR exceptions handling
public static class ExceptionExtensions
{
public static List<Exception> FlattenInnerExceptions(this Exception exception)
{
return exception
.DepthFirstSearchInnerExceptions()
.Distinct()
.Reverse()
.ToList();
}
@Zodt
Zodt / Program.cs
Last active October 3, 2022 05:32
C# Enumerate like in python through Extensions class
// C#9
using System;
using System.Collections.Generic;
foreach (var (value, index) in 5..10)
{
Console.WriteLine($"Value = {value.ToString()}, Index = {index.ToString()}");
}
public static class RangeExtensions