public static void Register(Type monadType, Type monadAdapterType) { var key = MonadHelpers.GetTypeOrGenericTypeDefinition(monadType); lock (LockObject) { Dictionary[key] = new MonadAdapterCache(monadAdapterType); } }
private static T GetInternal <T>(Type monadType, Func <MonadAdapterCache, T> cacheLookupFunc) { var key = MonadHelpers.GetTypeOrGenericTypeDefinition(monadType); lock (LockObject) { return(Dictionary.GetValue(key).Match(cacheLookupFunc, () => { throw new InvalidOperationException( string.Format("Could not find a registered monad adapter for {0}", key)); })); } }
public static MonoidAdapter <TW> Get <TW>(Type monoidType) { var key = MonadHelpers.GetTypeOrGenericTypeDefinition(monoidType); lock (LockObject) { var value = Dictionary.GetValue(key); return(value.Match( monoidAdapterCache => monoidAdapterCache.Get <TW>(), () => { throw new InvalidOperationException(string.Format("Could not find a registered monoid adapter for {0}", key)); })); } }
public MonadAdapterCache(Type monadAdapterType) { _monadAdapterType = MonadHelpers.GetTypeOrGenericTypeDefinition(monadAdapterType); }