This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
internal class InstanceReEntrancyGuard : IDisposable { | |
private class Ref<T> where T : struct { public T Value { get; set; } } | |
private static readonly ConditionalWeakTable<Object, Ref<Boolean>> reEntranceEphemerons = new ConditionalWeakTable<Object, Ref<Boolean>>(); | |
private readonly Ref<Boolean> hasEnteredOnce; | |
public InstanceReEntrancyGuard(Object instance, String reEntrantMessage = null) { | |
hasEnteredOnce = reEntranceEphemerons.GetValue(instance, x => new Ref<Boolean>()); | |
if (hasEnteredOnce.Value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[assembly:Ref.Ref.Ref, @ref.@ref.Ref] | |
namespace Ref { | |
[Ref, @ref.@ref.Ref] public struct Ref { | |
[Ref, @ref.@ref.Ref] public class RefAttribute : Attribute {} | |
[Ref, @ref.@ref.Ref] public Ref @ref([Ref, @ref.@ref.Ref] ref Ref @ref) { return @ref.@ref(ref @ref); } | |
} | |
} | |
namespace @ref { | |
[Ref, Ref.Ref.Ref] public class @ref { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[assembly:Out.Out.Out, @out.@out.Out] | |
namespace Out { | |
[Out, @out.@out.Out] public struct Out { | |
[Out, @out.@out.Out] public class OutAttribute : Attribute {} | |
[Out, @out.@out.Out] public Out @out([Out, @out.@out.Out] out Out @out) { return @out.@out(out @out); } | |
} | |
} | |
namespace @out { | |
[Out, Out.Out.Out] public class @out { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Reflection; | |
using System.Reflection.Emit; | |
public static class Struct { | |
public static Boolean ReferenceEquals<T>(ref T a, ref T b) where T : struct => Cache<T>.Func(ref a, ref b); | |
private static class Cache<T> where T : struct { | |
public delegate Boolean ReferenceEqualsDelegate(ref T a, ref T b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TypeSwitch : ReadOnlyTypeSwitch { | |
public TypeSwitch Case<T>(Action<T> action) { | |
matches.Add(typeof(T), x => action((T) x)); | |
return this; | |
} | |
public ReadOnlyTypeSwitch Default(Action @default) { | |
this.@default = @default ?? delegate { }; | |
return this; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
struct LightMutex { | |
private volatile Int32 inUse; | |
public void Lock() { | |
var spinWait = new SpinWait(); | |
while (Interlocked.Exchange(ref inUse, 1) == 1) | |
spinWait.SpinOnce(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using System.Windows.Input; | |
class AsyncCommand : ICommand { | |
public Boolean CanExecute(Object parameter = null) => !IsRunning; | |
public event EventHandler CanExecuteChanged = delegate { }; | |
public async void Execute(Object parameter = null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ISoftDeletable { | |
DateTime? Deleted { get; set; } | |
} | |
class MyEntity : ISoftDeletable { | |
public Int64 Id { get; set; } | |
public String Name { get; set; } | |
public DateTime? Deleted { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ImmutableArray<THandler> handlers = ImmutableArray<THandler>.Empty; | |
internal static void Add<THandler>(ref ImmutableArray<Action<THandler>> handlers, Action<THandler> handler) { | |
if (handler == null) | |
return; | |
ImmutableArray<Action<THandler>> initial, computed; | |
do { | |
initial = InterlockedGet(ref handlers); | |
computed = initial.Add(handler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IInnumerable { | |
// *crickets* | |
} |
OlderNewer