diff --git a/mustache-sharp/Properties/AssemblyInfo.cs b/mustache-sharp/Properties/AssemblyInfo.cs index d0e4d00..8e80552 100644 --- a/mustache-sharp/Properties/AssemblyInfo.cs +++ b/mustache-sharp/Properties/AssemblyInfo.cs @@ -14,6 +14,6 @@ using System.Runtime.InteropServices; [assembly: CLSCompliant(true)] [assembly: ComVisible(false)] [assembly: Guid("e5a4263d-d450-4d85-a4d5-44c0a2822668")] -[assembly: AssemblyVersion("0.2.6.0")] -[assembly: AssemblyFileVersion("0.2.6.0")] +[assembly: AssemblyVersion("0.2.7.0")] +[assembly: AssemblyFileVersion("0.2.7.0")] [assembly: InternalsVisibleTo("mustache-sharp.test")] \ No newline at end of file diff --git a/mustache-sharp/UpcastDictionary.cs b/mustache-sharp/UpcastDictionary.cs index 9d48ead..2015dda 100644 --- a/mustache-sharp/UpcastDictionary.cs +++ b/mustache-sharp/UpcastDictionary.cs @@ -24,24 +24,47 @@ namespace Mustache return getDictionary(types, source); } - private static IEnumerable getTypes(Type type) + private static IEnumerable getTypes(Type sourceType) { - HashSet types = new HashSet(); - getTypes(types, type); - return types; + Queue pending = new Queue(); + HashSet visited = new HashSet(); + pending.Enqueue(sourceType); + foreach (Type type in getTypes(pending, visited)) + { + yield return type; + } } - private static void getTypes(HashSet types, Type type) + private static IEnumerable getTypes(Queue pending, HashSet visited) { - if (type == null) + if (pending.Count == 0) { - return; + yield break; } - types.Add(type); - getTypes(types, type.BaseType); - foreach (Type interfaceType in type.GetInterfaces()) + + Type sourceType = pending.Dequeue(); + visited.Add(sourceType); + yield return sourceType; + + if (sourceType.BaseType != null) { - getTypes(types, interfaceType); + if (!visited.Contains(sourceType.BaseType)) + { + pending.Enqueue(sourceType.BaseType); + } + } + + foreach (Type interfaceType in sourceType.GetInterfaces()) + { + if (!visited.Contains(interfaceType)) + { + pending.Enqueue(interfaceType); + } + } + + foreach (Type type in getTypes(pending, visited)) + { + yield return type; } }