Skip to content

Instantly share code, notes, and snippets.

View Keboo's full-sized avatar

Kevin B Keboo

View GitHub Profile
@Keboo
Keboo / Person.cs
Last active March 12, 2019 06:05
AsyncLocal
public class Person
{
public string Name { get; set; }
}
public abstract class BindableBehavior<T> : Behavior<T> where T : BindableObject
{
protected override void OnAttachedTo(T bindable)
{
if (bindable != null)
{
this.InheritsBindingContextFrom(bindable);
}
base.OnAttachedTo(bindable);
}
@Keboo
Keboo / UnitTests
Created May 30, 2019 07:13
Create a delegate instance from its System.Type
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading.Tasks;
namespace CreateDelegate
{
[TestClass]
@Keboo
Keboo / Program.cs
Created May 5, 2020 04:19
Some GC thoughts on making sure objects are cleaned up.
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace GC
{
/*
In dotnet core, finalizer does not appear to be called on shutdown
@Keboo
Keboo / README.md
Last active July 2, 2020 00:02
Brain Teaser: Collection fun

Brain Teaser: Update the above code such that that unit tests pass. Do not update the content of the unit tests (however you are allowed to switch off of xUnit if you like).

@Keboo
Keboo / MultiBinding.cs
Last active September 17, 2020 07:18
A simple MultiBinding class for Xamarin.Forms. This "binding" only works when directly applied to an element.
/*
WARNING: This MultiBinding implementation only works when it is directly applied to its target property.
It will fail if used inside of a setter (such is the case when used within a trigger or style).
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
@Keboo
Keboo / BrainTeaser.cs
Last active September 20, 2020 04:46
Null constructor brain teaser. Simply replace ??? with any type that will cause the unit test to pass. Code used xUnit.
[Fact]
public static void NullReturnFromConstructor()
{
//Any Nullable<T> will work
Assert.Throws<InvalidOperationException>(() => SudoMakeMeSandwich<???>());
}
private static T SudoMakeMeSandwich<T>() where T : new()
{
return new T() ?? throw new InvalidOperationException();
@Keboo
Keboo / IHttpCall.cs
Last active September 22, 2020 15:59
In memory testing of HttpClient
namespace Example.HttpClient.Tests
{
public interface IHttpCall
{
int InvocationsCount { get; }
}
}
@Keboo
Keboo / ConstructorTests.cs
Last active September 1, 2021 06:39
Automatic testing of constructor parameters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Moq;
using Xunit;
namespace Namespace
{
public interface IConstructorTest
@Keboo
Keboo / App.xaml.cs
Created June 20, 2022 18:07
MarkupExtension with DI
public partial class App : Application
{
[NotNull]
public static IServiceProvider? ServiceProvider { get; private set; }
[STAThread]
public static void Main(string[] args)
{
using IHost host = CreateHostBuilder(args).Build();
host.Start();