Skip to content

Instantly share code, notes, and snippets.

View HaanstootZA's full-sized avatar

Hendrik Jacobs HaanstootZA

  • Johannesburg, South Africa
View GitHub Profile
public class DelegateEqualityComparer<T> : IEqualityComparer<T>
{
private readonly Func<T, T, bool> equalityPredicate;
private readonly Func<T, int> hashCodePredicate;
public DelegateEqualityComparer(Func<T, T, bool> equalityPredicate)
: this (equalityPredicate, null)
{
}
namespace example
{
public static class EnumerableHelper
{
public static bool In<T>(this T testValue, params T[] testParameters)
{
return testValue.In((left, right) => object.Equals(left, right), testParameters);
}
public static bool In<T>(this T testValue, Func<T, T, bool> testFunction, params T[] testParameters)
@HaanstootZA
HaanstootZA / PrimitiveHelper.cs
Last active May 5, 2020 08:59
A method of solving the problem of boxing/unboxing unknown objects and then comparing them
//A METHOD TO SOLVE THE BOXING/UNBOXING OF UNKNOWN OBJECTS COMPARISONS PROBLEM
//THIS IS NOT THE BEST WAY TO SOLVE THIS PROBLEM, I COULD ALSO USE A PROPER HEAP MEMORY MEMCMP BUT I'M AFRAID EVEYRONE MIGHT NOT KNOW C-LANG
//IT WOULD BE NICE IF ValueType.Equals WASN'T BEING AN ASSHOLE TO PRIMITIVES
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
private static class PrimitiveHelper
{
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
@HaanstootZA
HaanstootZA / FibonacciEnumerable.cs
Created February 13, 2020 13:38
An experiment on writing an enumerable implementation of the Fibonacci Principle.
using System.Collections;
using System.Collections.Generic;
namespace Fibonacci
{
public class FibonacciEnumerable : IEnumerable<ulong>
{
public IEnumerator<ulong> GetEnumerator()
{
return new FibonacciEnumerator(zeroValue: 0, firstValue: 1);
//Written by Hendrik Johann Jacobs see https://hjjacobs.com for some more of my stuff
using System;
using Microsoft.Extensions.Logging;
namespace Example
{
public static class LoggerExtensions
{
/// <summary>
/// <para>Log a unit of work, this denotes a single step within the current process and should be have an associated unit test.</para>