public void Test_Next() { Type type = typeof(TestArticle); TypeNavigator navigator = new TypeNavigator(type); ArrayList list = new ArrayList(); while (navigator.HasNext) { list.Add(navigator.Next()); } Assert.AreEqual(4, list.Count, "Invalid number of types identified."); }
/// <summary> /// Locates the reaction info for performing the specified action with the specified type by looking at the base types of the provided type. /// </summary> /// <param name="action">The action that is to be performed by the reaction.</param> /// <param name="type">The type that is involved in the action.</param> /// <returns>The reaction info for the specified scenario.</returns> public ReactionInfo[] LocateFromBaseTypes(string action, Type type) { ReactionInfoCollection reactionInfos = new ReactionInfoCollection(); // Logging commented out to boost performance //using (LogGroup logGroup = LogGroup.StartDebug("Locating reaction via the base types of the '" + (type != null ? type.FullName : "[null]") + "' type.")) //{ if (action == null) throw new ArgumentNullException("action"); if (action == String.Empty) throw new ArgumentException("An action must be specified."); if (type == null) throw new ArgumentNullException("type"); TypeNavigator navigator = new TypeNavigator(type); while (navigator.HasNext) { Type nextType = navigator.Next(); if (nextType != null) { //using (LogGroup logGroup2 = LogGroup.StartDebug("Checking base type: " + nextType.FullName)) //{ string key = Reactions.GetReactionsKey(action, nextType.Name); //LogWriter.Debug("Key: " + key); // If a reaction exists for the base type then use it if (Reactions.ReactionExists(key)) { if (Reactions.ContainsKey(key)) reactionInfos.AddRange(Reactions[key]); //LogWriter.Debug("Reactions found: " + reactionInfos.Count.ToString()); } //} } } //} return reactionInfos.ToArray(); }
/// <summary> /// Locates the strategy info for performing the specified action with the specified type by looking at the base types of the provided type. /// </summary> /// <param name="action">The action that is to be performed by the strategy.</param> /// <param name="type">The type that is involved in the action.</param> /// <returns>The strategy info for the specified scenario.</returns> public StrategyInfo LocateFromBaseTypes(string action, Type type) { StrategyInfo strategyInfo = null; //using (LogGroup logGroup = LogGroup.Start("Locating strategy via the base types of the provided type.", NLog.LogLevel.Debug)) //{ TypeNavigator navigator = new TypeNavigator(type); while (navigator.HasNext && strategyInfo == null) { Type nextType = navigator.Next(); if (strategyInfo == null) { // using (LogGroup logGroup2 = LogGroup.Start("Checking base type: " + nextType.FullName, NLog.LogLevel.Debug)) // { string key = StrategyInfo.GetStrategyKey(action, nextType.Name); // LogWriter.Debug("Key: " + key); // If a strategy exists for the base type then use it if (Strategies.StrategyExists(key)) { strategyInfo = Strategies[key]; // LogWriter.Debug("Strategy found: " + strategyInfo.StrategyType); } // TODO: Check if needed. It shouldn't be. The other call to LocateFromInterfaces in LocateFromHeirarchy should be sufficient // Otherwise check the interfaces of that base type //else //{ // strategyInfo = LocateFromInterfaces(action, nextType); //} // } } } //} return strategyInfo; }
/// <summary> /// Locates the controller info for performing the specified action with the specified type by looking at the base types of the provided type. /// </summary> /// <param name="action">The action that is to be performed by the controller.</param> /// <param name="type">The type that is involved in the action.</param> /// <returns>The controller info for the specified scenario.</returns> public ControllerInfo LocateFromBaseTypes(string action, Type type) { ControllerInfo controllerInfo = null; // Disabled logging to boost performance //using (LogGroup logGroup = LogGroup.Start("Locating via base types the controller for the action '" + action + "' and type '" + type.Name + "'.", NLog.LogLevel.Debug)) //{ TypeNavigator navigator = new TypeNavigator(type); while (navigator.HasNext && controllerInfo == null) { Type nextType = navigator.Next(); string key = Controllers.GetControllerKey(action, nextType.Name); // If a controller exists for the base type then use it if (Controllers.ControllerExists(key)) { // LogWriter.Debug("Found match with key: " + key); controllerInfo = Controllers[key]; break; } // TODO: Check if needed. It shouldn't be. The other call to LocateFromInterfaces in LocateFromHeirarchy should be sufficient // Otherwise check the interfaces of that base type //else //{ // controllerInfo = LocateFromInterfaces(action, nextType); //} } //} return controllerInfo; }