Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace crap
{
using System;
using System.Collections.Generic;
using System.Data;
namespace crap
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class PartialAppPlayground
{
private static Dispatcher<IHandlerResult> _dispatcher;
public class Dispatcher<TMessage, TResult>
{
private readonly Dictionary<Type, Func<TMessage, TResult>> _dictionary = new Dictionary<Type, Func<TMessage, TResult>>();
public void Register<T>(Func<T, TResult> func) where T : TMessage
{
_dictionary.Add(typeof(T), x => func((T)x));
}
public TResult Dispatch(TMessage m)
public class Nothing
{
private Nothing() {}
public static readonly Nothing Value=new Nothing();
public override string ToString()
{
return "Nothing";
}
}
@gregoryyoung
gregoryyoung / gist:7677790
Created November 27, 2013 15:40
command handling with same dispatcher
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace crap
{
using System;
using System.Collections.Generic;
using System.Data;
@gregoryyoung
gregoryyoung / gist:7690486
Created November 28, 2013 11:31
updated to support actions to funcs
namespace crap
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class PartialAppPlayground
public static ArraySegment<byte> Serialize<T>(this T protoContract)
{
using (var memory = new MemoryStream())
{
Serializer.Serialize(memory, protoContract);
var res = new ArraySegment<byte>(memory.GetBuffer(), 0, (int) memory.Length);
return res;
}
}
var o =
JArray.Parse(@"[
{
""eventId"": ""fbf4a1a1-b4a3-4dfe-a01f-ec52c34e16e4"",
""eventType"": ""event-type"",
""data"": {
""BirthDate"": ""1987-11-07T00:00:00.000+01:00""
}
}
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
DateParseHandling = DateParseHandling.None
};
var foo = JsonConvert.DeserializeObject(@"[
{
""eventId"": ""fbf4a1a1-b4a3-4dfe-a01f-ec52c34e16e4"",
""eventType"": ""event-type"",
""data"": {
==20921== 2350 errors in context 22 of 32:
==20921== Conditional jump or move depends on uninitialised value(s)
==20921== at 0x51369C: sgen_sort_addresses (sgen-gc.c:1447)
==20921== by 0x52B879: sgen_optimize_pin_queue (sgen-pinning.c:154)
==20921== by 0x514803: major_copy_or_mark_from_roots (sgen-gc.c:2855)
==20921== by 0x515265: major_do_collection (sgen-gc.c:3277)
==20921== by 0x518F47: sgen_perform_collection (sgen-gc.c:3461)
==20921== by 0x51A8F4: sgen_los_alloc_large_inner (sgen-los.c:346)
==20921== by 0x50B1B2: mono_gc_alloc_obj_nolock (sgen-alloc.c:204)
==20921== by 0x50B6D7: mono_gc_alloc_vector (sgen-alloc.c:491)