Skip to content

Instantly share code, notes, and snippets.

@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)
@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
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 / 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 / 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 / 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 / Test.cs
Last active February 5, 2016 11:00
slow assertion
// The Property Culture is of type CultureInfo
enumarableOfComplexObject.ShouldAllBeEquivalentTo(
new[]
{
new { RefText = "Ref1", Culture = Invariant, Text = "Ref1 en", Component = string.Empty },
new { RefText = "Ref3", Culture = Invariant, Text = "Ref3 en", Component = string.Empty },
new { RefText = "Ref1", Culture = German, Text = "Ref1 de", Component = string.Empty },
new { RefText = "Ref3", Culture = German, Text = "Ref3 de", Component = string.Empty },
new { RefText = "Ref1", Culture = English, Text = "Ref1 en", Component = string.Empty },
new { RefText = "Ref3", Culture = English, Text = "Ref3 en", Component = string.Empty },
@bitbonk
bitbonk / PareserTests.cs
Last active November 30, 2015 18:15
Can I have one Should() instead of two?
using System;
using System.Collections;
using System.Linq;
using FluentAssertions;
using Xunit;
public class ParserTests
{
[Theory,
InlineData(DataType.String, "foo", "foo"),
[TestMethod]
public void AssertNestedInnerException()
{
var expectedExcpetion = new Exception();
new Action(
() =>
{
throw new InvalidOperationException("", new KeyNotFoundException("", expectedExcpetion));
})
[TestMethod]
public void AssertNestedInnerException()
{
var expectedExcpetion = new Exception();
new Action(
() =>
{
throw new InvalidOperationException("", new KeyNotFoundException("", expectedExcpetion));
})