Skip to content

Instantly share code, notes, and snippets.

@iSynaptic
iSynaptic / gist:5406562
Created April 17, 2013 18:26
Two way bi-direction reference between immutable objects...
using System;
namespace Example
{
class Program
{
static void Main(string[] args)
{
var theA = new A(a => new B(a));
var theB = theA.TheB;
Outcome.Success()
.FailIf(true, "failed")
.Let(x =>
{
if(x.WasSuccessful)
{
return x & Outcome.FailIf(true, "this is the expensive check");
}
return x;
public static class Validator
{
public static Outcome<string> ValidatePassword(IDssPrincipal principal, string password)
{
const int minimumLength = 8;
const int maximumLength = 20;
return Outcome.Success()
// Password cannot be empty
public static class Validator
{
public static Outcome<string> ValidatePassword(IDssPrincipal principal, string password)
{
Outcome<string> result = Outcome.Success();
Maybe<string> email = principal.ToMaybe()
.Select(x => x.Identity)
.Select(x => x.EmailAddress);
// Password cannot be empty
@iSynaptic
iSynaptic / gist:2323837
Created April 6, 2012 23:09
Windows to Olson TimeZone Conversion via NodaTime
foreach (var windowsTimeZone in TimeZoneInfo.GetSystemTimeZones())
{
var olsonTimeZoneProvider = new TzdbTimeZoneProvider("NodaTime.TimeZones.Tzdb");
var olsonTimeZone = olsonTimeZoneProvider.MapTimeZoneId(windowsTimeZone);
Console.WriteLine(olsonTimeZone ?? string.Format("{{{0}}}", windowsTimeZone.Id));
}
@iSynaptic
iSynaptic / Example.cs
Created July 11, 2011 19:10
Exodata example for Jason Bock
// Create a declaration
public static class Declarations
{
public static readonly ExodataDeclaration<bool> IsValidator = new ExodataDeclaration<bool>(default: false);
}
// code to define
Bind(Declarations.IsValidator)
.Given<string>()
.For<Type>()
using System;
using System.Diagnostics;
using Ninject;
namespace ScratchPad
{
public class Foo : IBoo, IBaz
{
}