Skip to content

Instantly share code, notes, and snippets.

@distantcam
distantcam / IEndpointDefinition.cs
Last active January 9, 2023 08:23
C# 11 Static Endpoint Mapping
public interface IEndpointDefinition
{
static abstract void MapEndpoint(IEndpointRouteBuilder builder);
}
public static class EndpointRouteBuilderExtensions
{
private static readonly MethodInfo MapEndpointMethod = typeof(EndpointRouteBuilderExtensions).GetMethod(nameof(MapEndpoint), BindingFlags.NonPublic | BindingFlags.Static)!;
private static void MapEndpoint<T>(IEndpointRouteBuilder builder) where T : IEndpointDefinition => T.MapEndpoint(builder);
@distantcam
distantcam / EcsRx_StrongInject.csproj
Created July 2, 2021 15:43
A small EcsRx + StrongInject example
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EcsRx" Version="5.0.101" />
<PackageReference Include="EcsRx.Plugins.ReactiveSystems" Version="5.0.101" />
@distantcam
distantcam / StripIsExternalInitWeaver.cs
Created December 10, 2020 05:03
A Fody weaver to strip C# 9 records markers so the assembly is compatible with C# 8 / Xamarin mono build tools.
using System.Collections.Generic;
using System.Linq;
using Fody;
using Mono.Cecil;
public class StripIsExternalInitWeaver : BaseModuleWeaver
{
public override void Execute()
{
var types = ModuleDefinition.Types.Concat(ModuleDefinition.Types.SelectMany(t => t.NestedTypes));
0eNrtnU1vJEeSpv9Kg5e9FIXwb3cdp08L7GkwhwEWi0aVRGiILlUVWCxhGg3+92UmM1mpTLOI94nM1GgGvHRDVOQjD3cLd3Nzc3v/efPh47e7Lw/3nx7/9uHz57/f/PjP73/5evPj/z34x82/+/rp/Zfbx8+3vzzc/7z55/+8+TFM07ubf2z//+ndzfsPXz9//PZ4d7t58sv9p19ufnx8+Hb37ub+p8+fXoBf73/59P7j5teP//hyd/PjzW/3D4/fnv/y7ubT+183f3h54vZ/3zwD7z/9fLf5rzy9M355/3j36/efPby//3jwk8h/kpSffP7w+cvnh8eDn+Wn//fu5u7T4/3j/d3LO27/4R9/+/Tt1w93D8+t//5qv77/+PH24/tfvzwTv3z++vyTz592PXmbfyjbrrytP5SnTVOOMFHCLFGSRBllAZMlTJiWmlO0vql7TLYx9RXz4f6X27uPdz89Ptz/dPvl88c7g7ZjlecxfLbLT88P32/N8583YfM/D3c/Hw7jxtbbwX9z889x2gz6Lw93d5+UR5+sNjfSZt7ketSOMB03LLjvIP3WfKkujefScA6JktICJkyki9P5ZhGSbBabR80eDNp0kZb6MGjzRV3sxEQ6sfJOPDGuUN1eNJ+1u1GboepiN2oz1FjsRjRFjRXdmI675mQmGn6/Sj+2OxrNY2Fa8WbH01HyZ1/zWbvdXVzCFi1ksDXMwcRpxRp2xnoQw9EfSpbXA/O3Zi/HwFc58FLxeD44Mdt83NLivuU6mP3aEa2Dnkkktg56mLxiGSSDcGwN0Z/AzWftLixsHfRevq5YvsjLZ32WNZ+1X76x1ct7+c4WLw8zVqxdpA/r6ap+MosffXkzvbyOZo5DmtYsbuTVx9LCW/3FTvux/WIBrn6OaaTINrferjShza1HyWxz62EK3Nx6nHoaNjihxBdEtAlNILRZQicGvJkvNqhuotAs0OIMKk+/i8Hc7oIup+M9dj2cwg+bj+rn+4eXb2oX3znGwkjLZuE0m8d
@distantcam
distantcam / extensions.json
Created March 28, 2019 07:15
Presentation settings for vscode
{
"recommendations": [
"saviorisdead.theme-githubcleanwhite",
"evilz.vscode-reveal"
]
}
using Unity.Entities;
using Unity.Jobs;
public abstract class CompositeParallelJobSystem<T1, T2> : JobComponentSystem
where T1 : struct, IJobParallelFor
where T2 : struct, IJobParallelFor
{
protected ComponentGroup group;
protected abstract ComponentGroup CreateGroup();
@distantcam
distantcam / JobHelper.cs
Last active August 17, 2023 15:54
Unity Job system with async
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Unity.Jobs;
public static class JobHelper
{
@distantcam
distantcam / Sample.csproj
Created October 19, 2017 03:27
Example new project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<DebugType>full</DebugType>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
@distantcam
distantcam / SimpleConfig.cs
Created October 12, 2017 08:57
Simple config class
public static class SimpleConfig
{
static string configFilePath;
public static void InitializeInLocalApplicationData(string name)
{
Initialize(Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
name,
"config.xml"
using System.ComponentModel;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Exporters;
using BenchmarkDotNet.Running;
[MemoryDiagnoser]
[MarkdownExporter]
public class PropertyChangedArgBenchmarks
{