Skip to content

Instantly share code, notes, and snippets.

@bitbonk
bitbonk / List.cs
Created November 25, 2016 08:37
ctor geruden von ToList()
public List(IEnumerable<T> collection)
{
if (collection == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
ICollection<T> objs = collection as ICollection<T>;
if (objs != null)
{
int count = objs.Count;
if (count == 0)
{
@bitbonk
bitbonk / deploy.ps1
Created January 10, 2017 09:12
deploy something but exclude some stuff
<#
.SYNOPSIS
Copies the files that belong to a deployment to a target folder.
.PARAMETER Source
The path of the source folder.
.PARAMETER Target
The path of the target folder.
#>
[CmdletBinding(SupportsShouldProcess=$True)]
@bitbonk
bitbonk / Program.cs
Last active September 29, 2017 21:13
Host ScriptCs in a console application and install a script pack at startup
namespace ConsoleHostedScriptCs
{
using System;
using Common.Logging.Simple;
using NuGet;
using ScriptCs.Contracts;
using ScriptCs.Engine.Roslyn;
using ScriptCs.Hosting;
using PackageReference = ScriptCs.PackageReference;
@bitbonk
bitbonk / Clients.cs
Created November 6, 2018 16:27
very simple signalr server + client
class Program
{
static async Task Main(string[] args)
{
var connection = new HubConnectionBuilder().WithUrl("http://localhost:19715/chat")
.Build();
await connection.StartAsync();
var receiveCounter = 0;
var isReceiver = args.Length < 1 || args[0].ToLower() != "sender";
@bitbonk
bitbonk / Program.cs
Created January 19, 2019 18:23
Hello World System.Threading.Channels
using System;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
class Program
{
public static async Task Main(string[] args)
{
var channel =
@bitbonk
bitbonk / NETClassic.json
Last active January 21, 2019 21:26
JSON Deserailization .NET Core vs. .NET Classic
{
"$type": "MyNamespace.Dto`6[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], NETClassicApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"StringProp": "my string",
"DoubleProp": 123.0,
"FloatProp": 345.0,
"ByteArrayProp": {
"$type": "System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"$value": "AQID"
},
"UriProp": "http://localhost:80",
@bitbonk
bitbonk / Program.cs
Last active February 8, 2019 15:51
System.Threading.Channels (C# 8)
namespace ChannelTest
{
using System;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
class Program
{
public static async Task Main(string[] args)
private Task completion = Task.CompletedTask;
private int counter;
private void ButtonOnClick(object sender, RoutedEventArgs e)
{
this.completion = this.completion.ContinueWith(async _ =>
{
this.counter = this.counter + 1;
Debug.WriteLine($"Enter ButtonOnClick {counter}");
await DoSubAsync(counter);
@bitbonk
bitbonk / 1. MainWindow.cs
Last active June 28, 2019 13:44
async v1
private int counter = 0;
private async void ButtonOnClick(object sender, RoutedEventArgs e)
{
counter = counter + 1;
Debug.WriteLine($"Enter ButtonOnClick {counter}");
await DoSubAsync(counter);
Debug.WriteLine($"Exit ButtonOnClick {counter}");
}
public async Task DoSubAsync(int number)
{
@bitbonk
bitbonk / 1. MainWindow.cs
Last active June 28, 2019 13:59
async v3
private Task completion = Task.CompletedTask;
private int counter;
private async void ButtonOnClick(object sender, RoutedEventArgs e)
{
this.completion = this.completion.ContinueWith(async _ =>
{
this.counter = this.counter + 1;
Debug.WriteLine($"Enter ButtonOnClick {counter}");
await DoSubAsync(counter);