Skip to content

Instantly share code, notes, and snippets.

@shadow-cs
shadow-cs / LambdaVsMethod.cs
Created August 20, 2021 13:14
A benchmark for using various methods of passing a delegate
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<Benchmark>();
[MemoryDiagnoser]
public class Benchmark
{
private static int Executor(Func<int> a) => a();
@shadow-cs
shadow-cs / JsonSchemaLoader.cs
Created September 30, 2020 07:13
Loading external $ref schemas using json-everything
// See https://github.com/gregsdennis/json-everything/issues/8
public class JsonSchemaLoader
{
private static JsonSchema Load(string schemaFile, ValidationOptions options)
{
var schemaFullPath = Path.GetFullPath(schemaFile);
var schemaUri = new Uri(schemaFullPath);
var json = File.ReadAllText(schemaFile);
return Load(schemaUri, json, options);
@shadow-cs
shadow-cs / NetMQTest.csproj
Last active February 13, 2020 08:50
NetMQ async exceptions
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
@shadow-cs
shadow-cs / Counter.cs
Created November 9, 2019 13:46
Blazor Code behind
namespace CodeBehindTest.Pages
{
public partial class Counter
{
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
@shadow-cs
shadow-cs / Items.targets
Last active November 18, 2021 09:43
MSBuild: Selecting first and last items in an ItemGroup
<Project DefaultTargets="Default">
<ItemGroup>
<Items Include="One;Two;Three;Four;Five" />
</ItemGroup>
<Target Name="Default">
<ItemGroup>
<Reversed Include="@(Items->Reverse())" />
</ItemGroup>