Ejemplo n.º 1
0
        public static void Register(Type monadType, Type monadAdapterType)
        {
            var key = MonadHelpers.GetTypeOrGenericTypeDefinition(monadType);

            lock (LockObject)
            {
                Dictionary[key] = new MonadAdapterCache(monadAdapterType);
            }
        }
Ejemplo n.º 2
0
        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));
                }));
            }
        }
Ejemplo n.º 3
0
        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));
                }));
            }
        }
Ejemplo n.º 4
0
 public MonadAdapterCache(Type monadAdapterType)
 {
     _monadAdapterType = MonadHelpers.GetTypeOrGenericTypeDefinition(monadAdapterType);
 }