예제 #1
0
 /// <summary>
 /// Gets a dispatcher from the cache if available otherwise
 /// invokes factory to produce one and then cache it.
 /// </summary>
 /// <param name="key">the dispatcher key</param>
 /// <param name="factory">function to produce a dispatcher in case one it's not yet available</param>
 /// <returns></returns>
 public Dispatcher Get(DispatcherKey key, DispatcherFactory factory)
 {
     Dispatcher dispatcher;
     if (!_cache.TryGetValue(key, out dispatcher))
     {
         lock (_cache)
         {
             if (!_cache.TryGetValue(key, out dispatcher))
             {
                 dispatcher = factory();
                 _cache.Add(key, dispatcher);
             }
         }
     }
     return dispatcher;
 }
예제 #2
0
		private static Dispatcher GetDispatcher(object target, string cacheKeyName, Type[] cacheKeyTypes, DispatcherCache.DispatcherFactory factory)
		{
			var targetType = (target as Type) ?? target.GetType();
			var key = new DispatcherKey(targetType, cacheKeyName, cacheKeyTypes);
			return _cache.Get(key, factory);
		}
예제 #3
0
 private static object Dispatch(object target, string cacheKeyName, Type[] cacheKeyTypes, object[] args, DispatcherCache.DispatcherFactory factory)
 {
     Type targetType = (target as Type) ?? target.GetType();
     DispatcherKey key = new DispatcherKey(targetType, cacheKeyName, cacheKeyTypes);
     Dispatcher dispatcher = _cache.Get(key, factory);
     return dispatcher(target, args);
 }