/// <summary> /// Walks through profile nodes recursively, /// TagProcessingDelegate is called for every Tag. /// The original tag is replaced by tag returned by TagProcessingDelegate /// </summary> public static void RecurseBehaviors(IList<ProfileBehavior> nodes, TagProcessingDelegate replacementDelegate, int depth = 0, int maxDepth = 20) { if (nodes == null || !nodes.Any()) return; if (replacementDelegate == null) return; if (depth == maxDepth) { Core.Logger.Debug("MaxDepth ({0}) reached on ProfileUtils.ReplaceBehaviors()", maxDepth); return; } for (var i = 0; i < nodes.Count; i++) { if (nodes[i] == null) continue; var node = nodes[i]; var type = node.GetType(); nodes[i] = replacementDelegate.Invoke(node, i, type); if (nodes[i] == null) continue; if (node is INodeContainer) { RecurseBehaviors((node as INodeContainer).GetNodes() as List<ProfileBehavior>, replacementDelegate, depth + 1, maxDepth); } } }
/// <summary> /// Walks through profile nodes recursively, /// TagProcessingDelegate is called for every Tag. /// The original tag is replaced by tag returned by TagProcessingDelegate /// </summary> public static void RecurseBehaviors(IList <ProfileBehavior> nodes, TagProcessingDelegate replacementDelegate, int depth = 0, int maxDepth = 20) { if (nodes == null || !nodes.Any()) { return; } if (replacementDelegate == null) { return; } if (depth == maxDepth) { Logger.Debug("MaxDepth ({0}) reached on ProfileUtils.ReplaceBehaviors()", maxDepth); return; } for (var i = 0; i < nodes.Count(); i++) { if (nodes[i] == null) { continue; } var node = nodes[i]; var type = node.GetType(); nodes[i] = replacementDelegate.Invoke(node, i, type); if (nodes[i] == null) { continue; } var newType = nodes[i].GetType(); //if (QuestTools.EnableDebugLogging) // Logger.Debug("".PadLeft(depth * 5) + "{0}> {1}", depth, newType != type ? // string.Format("replaced {0} with {1}", type, newType) : // string.Format("ignored {0}", newType) // ); if (node is INodeContainer) { RecurseBehaviors((node as INodeContainer).GetNodes() as List <ProfileBehavior>, replacementDelegate, depth + 1, maxDepth); } } }