/// <summary> /// Gets a reference to the generic "FindBy" method of the given finder /// for the given message type using a hashtable lookup rather than reflection. /// </summary> /// <param name="finder"></param> /// <param name="message"></param> /// <returns></returns> public static MethodInfo GetFindByMethodForFinder(IFinder finder, object message) { MethodInfo result = null; IDictionary <Type, MethodInfo> methods; FinderTypeToMessageToMethodInfoLookup.TryGetValue(finder.GetType(), out methods); if (methods != null) { methods.TryGetValue(message.GetType(), out result); if (result == null) { foreach (Type messageType in methods.Keys) { if (messageType.IsInstanceOfType(message)) { result = methods[messageType]; } } } } return(result); }
static void ConfigureFinder(Type t) { foreach (Type interfaceType in t.GetInterfaces()) { Type[] args = interfaceType.GetGenericArguments(); if (args.Length != 2) { continue; } Type sagaEntityType = null; Type messageType = null; foreach (Type typ in args) { if (typeof(IContainSagaData).IsAssignableFrom(typ)) { sagaEntityType = typ; } if (MessageConventionExtensions.IsMessageType(typ) || typ == typeof(object)) { messageType = typ; } } if (sagaEntityType == null || messageType == null) { continue; } Type finderType = typeof(IFindSagas <> .Using <>).MakeGenericType(sagaEntityType, messageType); if (!finderType.IsAssignableFrom(t)) { continue; } FinderTypeToSagaEntityTypeLookup[t] = sagaEntityType; MethodInfo method = t.GetMethod("FindBy", new[] { messageType }); IDictionary <Type, MethodInfo> methods; FinderTypeToMessageToMethodInfoLookup.TryGetValue(t, out methods); if (methods == null) { methods = new Dictionary <Type, MethodInfo>(); FinderTypeToMessageToMethodInfoLookup[t] = methods; } methods[messageType] = method; } }
/// <summary> /// Gets a reference to the generic "FindBy" method of the given finder /// for the given message type using a hashtable lookup rather than reflection. /// </summary> /// <param name="finder"></param> /// <param name="message"></param> /// <returns></returns> public static MethodInfo GetFindByMethodForFinder(IFinder finder, object message) { MethodInfo result = null; IDictionary<Type, MethodInfo> methods; FinderTypeToMessageToMethodInfoLookup.TryGetValue(finder.GetType(), out methods); if (methods != null) { methods.TryGetValue(message.GetType(), out result); if (result == null) foreach (Type messageType in methods.Keys) if (messageType.IsAssignableFrom(message.GetType())) result = methods[messageType]; } return result; }