Skip to content

Instantly share code, notes, and snippets.

View Powerz's full-sized avatar

Aleksei Zagoskin Powerz

View GitHub Profile
@Powerz
Powerz / resharper-nunit-live-templates.cs
Created November 14, 2016 09:55
Resharper live templates for NUnit
[Test]
public void Should_$TESTNAME$()
{
// arrange
$END$
// act
// assert
@Powerz
Powerz / IsolatedDomainScope.cs
Created December 8, 2016 12:25
Run a method in another application domain
public class IsolatedDomainScope<T> : IDisposable where T : new()
{
private AppDomain _domain;
public IsolatedDomainScope()
{
_domain = AppDomain.CreateDomain("IsolatedDomainScope:" + Guid.NewGuid(), null, AppDomain.CurrentDomain.SetupInformation);
var type = typeof(T);
Value = (T) _domain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
@Powerz
Powerz / resharper-xunit-live-templates.cs
Last active May 19, 2023 17:05
Resharper live templates for xUnit
[Fact]
public void Should_$TESTNAME$()
{
//! Arrange
$END$
//! Act
//! Assert
@Powerz
Powerz / DuckTyping.cs
Last active January 12, 2023 21:53
Duck Typing implementation. Return property value by property name.
using System.Collections.Concurrent;
using System.Reflection;
public static class DuckTyping
{
private static readonly ConcurrentDictionary<string, PropertyInfo?> _cache = new();
public static object? Get(this object? obj, string propName)
{
if (obj == null) return null;
@Powerz
Powerz / LoggingAdapter.cs
Created August 16, 2018 13:03
ILogger<T> for old ASP.NET (not Core)
// Bind ILoggerFactory to LoggerFactory
// Bind typeof(ILogger<>) to typeof(LoggingAdapter<>)
public class LoggingAdapter<T> : ILogger<T>
{
private readonly Microsoft.Extensions.Logging.ILogger _logger;
public LoggingAdapter(ILoggerFactory factory)
{
_logger = factory.CreateLogger<T>();
@Powerz
Powerz / EnumExtensions.cs
Last active January 12, 2023 21:49
Get enum description by enum member
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Reflection;
public static class EnumExtensions
{
private static readonly ConcurrentDictionary<string, string> _descriptionsByEnumMemberName = new();
public static string GetDescription<T>(this T value) where T : Enum
{
@Powerz
Powerz / .editorconfig
Created October 20, 2018 14:21
C# EditorConfig file (.editorconfig)
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017#formatting-conventions
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2017
# https://github.com/dotnet/roslyn/blob/master/.editorconfig
# https://medium.com/@jonjam/c-code-style-using-editorconfig-9d38de65527d
# https://github.com/kentcb/EditorConfigReference/blob/master/.editorconfig
# https://github.com/RehanSaeed/EditorConfig/blob/master/.editorconfig
# https://www.jetbrains.com/help/rider/Using_EditorConfig.html
@Powerz
Powerz / update-notification.sh
Created May 14, 2019 17:10
Push notifications for ASUS router with Merlin firmware
#!/bin/sh
### Do not change below
# Retrieve version
TMPVERS=$(nvram get webs_state_info)
echo "$TMPVERS" | grep 382
if [ $? -ne 0 ]; then
VERS=${TMPVERS:5:3}.${TMPVERS:8:10}
else
VERS=$TMPVERS
@Powerz
Powerz / ResharperTemplates.DotSettings
Last active March 24, 2021 06:40
Resharper / Rider file templates for FluentMigrator and live templates for xUnit
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/QuickList/=F0CA621CDF5AB24282D8CDC11C520997/Entry/=202E5F32AF467445AA17792D97AF1C26/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/QuickList/=F0CA621CDF5AB24282D8CDC11C520997/Entry/=202E5F32AF467445AA17792D97AF1C26/EntryName/@EntryValue">ForwardOnlyMigration</s:String>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/QuickList/=F0CA621CDF5AB24282D8CDC11C520997/Entry/=202E5F32AF467445AA17792D97AF1C26/Position/@EntryValue">6</s:Int64>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/QuickList/=F0CA621CDF5AB24282D8CDC11C520997/Entry/=2CBD6971A7955044AD2624B84FB49E38/Position/@EntryValue">11</s:Int64>
<s:
@Powerz
Powerz / AutoMapperTestsBase.cs
Created January 12, 2023 21:33
Base classes for testing AutoMapper profiles using Autofixture.
using AutoFixture;
using AutoMapper;
/// <summary>
/// Base class for AutoMapper tests (one profile).
/// </summary>
/// <typeparam name="TProfile">Mappings profile</typeparam>
public abstract class AutoMapperTestsBase<TProfile> where TProfile : Profile, new()
{
protected readonly Fixture Fixture;