Skip to content

Instantly share code, notes, and snippets.


Vladimir Kozlov aienabled

View GitHub Profile
aienabled / EqualityBenchmark.cs
Last active Jan 7, 2021
A C# console program to microbenchmark equality methods. It confirms that there is NO performance difference with `ReferenceEquals` and `==` operator for reference type (class).
View EqualityBenchmark.cs
using BenchmarkDotNet.Attributes;
public class EqualityBenchmark
private const int NumberOfComparisons = 100000;
public string EqualityWithOperator()
var a = new Foo();
View DeviceStateHelperD3D11.cs
namespace NoesisGUI.MonoGameWrapper.Helpers.DeviceState
using System;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using SharpDX.Mathematics.Interop;
using Buffer = SharpDX.Direct3D11.Buffer;
using Device = SharpDX.Direct3D11.Device;
View LerpWithDeltaTime.cs
// see
public static double LerpWithDeltaTime(double a, double b, double deltaTime, double rate)
return Lerp(b, a, Math.Pow(2, -rate * deltaTime));
// see
public static float LerpWithDeltaTime(float a, float b, float deltaTime, float rate)
return Lerp(b, a, Math.Pow(2, -rate * deltaTime));
aienabled / Convert-ToPackageReference.ps1
Last active Oct 12, 2017 — forked from a4099181/Convert-ToPackageReference.ps1
Converts packages.config into PackageReference at *.csproj project file. Requires XSLT stylesheet available as second file in the gist.
View Convert-ToPackageReference.ps1
Function Convert-ToPackageReference
Param ( [Parameter( Mandatory, ValueFromPipeline )][String] $inputUri,
[String] $stylesheetUri = "",
[String] $resultsFile = [System.IO.Path]::GetTempFileName() )
Process {
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform
$xslt.Load( $stylesheetUri )
$xslt.Transform( $inputUri, $resultsFile )
aienabled / C# 7.0 ReSharper
Last active Mar 8, 2017
C# 7.0 pattern matching rewriter for ReSharper (search and replace with pattern, automatic replace)
View C# 7.0 ReSharper

C# 7.0 brings many syntax improvements and features. One of the most valuable is the new pattern matching syntax. Usually it's used with switch blocks but it has another great use with if conditions. Currently there are no auto-replacement or auto-suggestion for that case in ReSharper yet (at current version 2017.1 EAP 2), but we could easily add it. But first let's consider the problem and improvements C# 7.0 brings us.

Pattern matching at if statement with is operator

For example, consider this code:

if (obj is FooType)
 var fooObj = (FooType)obj;
aienabled / RoslynWpfToNoesisPreprocessor.cs
Created Feb 16, 2017
Preprocessor to make C# code for WPF compatible with NoesisGUI (replace System.Windows namespaces)
View RoslynWpfToNoesisPreprocessor.cs
public static SyntaxNode ProcessSyntaxTree(
SyntaxTree syntaxTree,
ConcurrentStack<Diagnostic> syntaxTreeProcessingMessages)
var replacementsDict = new Dictionary<SyntaxNode, SyntaxNode>(0);
var root = (CompilationUnitSyntax)syntaxTree.GetRoot();
foreach (var usingNode in root.DescendantNodes().OfType<UsingDirectiveSyntax>())
var ns = usingNode.Name.GetText().ToString();
aienabled / AvoidUnityVisualStudioSolutionRegeneration.cs
Last active Dec 28, 2015
Avoid (re)generation of the Unity VisualStudio solution file for Unity 5.2+
View AvoidUnityVisualStudioSolutionRegeneration.cs
using SyntaxTree.VisualStudio.Unity.Bridge.Configuration;
using UnityEditor;
/// <summary>
/// Avoid (re)generation of the solution file
/// Unfortunately this settings is hidden since Unity 5.2 (when UnityVS was integrated into VS)
/// HOW TO USE: place into your Assets/Editor folder.
/// </summary>