Skip to content

Instantly share code, notes, and snippets.

View benaadams's full-sized avatar
🦆
rubber duck debugging

Ben Adams benaadams

🦆
rubber duck debugging
View GitHub Profile
@benaadams
benaadams / modernizing-csharp9.md
Last active November 11, 2020 11:50 — forked from richlander/modernizing-csharp9.md
Modernizing a codebase for C# 9

Modernizing a codebase for C# 9

There are lots of cases that you can improve. The examples use nullable reference types, but only the WhenNotNull example requires it.

Use the property pattern to replace IsNullorEmpty

Consider adopting the new property pattern, wherever you use IsNullOrEmpty.

string? hello = "hello world";
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using static Microsoft.AspNetCore.Builder.ArgumentType;
namespace Microsoft.AspNetCore.Builder
{
public static class RequestDelegateExtensions
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
namespace delegate_interface
{
public class Program : IFoo
{
const int InnerLoopCount = 10000;
const int maxBuffer = 1024;
while (true)
{
var result = await application.Output.ReadAsync();
var buffer = result.Buffer;
// Check if we have enough to perform a write
if (buffer.Length >= maxBuffer)
{
@benaadams
benaadams / Program.cs
Last active February 15, 2018 03:04 — forked from abdullin/LICENSE
Naive ring benchmark in .NET Core using simulated actors
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace SimRing {
class Program {
static void Main(string[] args) {
const int n = 1000;
const int m = 1000;
@benaadams
benaadams / Startup.cs
Created August 25, 2017 04:40 — forked from malekpour/Startup.cs
Iris Go vs .NET Core Kestrel in terms of HTTP performance
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore;
using Microsoft.Extensions.DependencyInjection;
public class Startup
{
@benaadams
benaadams / IListPerformance.cs
Last active December 5, 2018 22:12 — forked from Thealexbarney/IListPerformance.cs
Simple IList performance benchmark
using System;
using System.Collections.Generic;
using System.Collections;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace IListPerformance
{
public class Program
{
@benaadams
benaadams / Odd results?
Last active January 19, 2017 02:52 — forked from Drawaes/Odd results?
public static void Main(string[] args)
{
var x = Flip(10000);
var y = FlipNew(10000);
////var bench = new ReverseBench();
////bench.FlipInSets64Bit();
//BenchmarkRunner.Run<ReverseBench>();
}
public unsafe static ulong Flip(ulong data)
using BenchmarkDotNet.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Configs;
@benaadams
benaadams / TextureData.cs
Last active April 9, 2016 02:46 — forked from jessefreeman/TextureData.cs
A class that emulates the API of Unity's Texture2D but uses int as references to color index instead of the color class.
using System;
namespace PixelVision.Engine.Chips.Graphics.Sprites
{
public interface ITextureData
{
int Width { get; }
int Height { get; }
int GetPixel(int x, int y);
void SetPixel(int x, int y, int value);