From 26986f95693b51a9880a6c18da6db6650c6c3af5 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 5 Jun 2011 02:40:48 +0200 Subject: [PATCH] Make sure NamespaceEntry.ClassCount stays consistent with the ordinal typeDict at all times, even when there are name clashes in one of the non-ordinal dictionaries. --- .../TypeSystem/Implementation/TypeStorage.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/TypeStorage.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/TypeStorage.cs index d7598a53a5..161bf0e15f 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/TypeStorage.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/TypeStorage.cs @@ -121,7 +121,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation public readonly NamespaceEntry Parent; /// - /// Number of classes in this namespace (not in sub-namespaces) + /// Number of classes in this namespace (not in sub-namespaces). + /// Note: this always refers to the number of classes from the ordinal typeDict that map + /// to this namespace when compared with the appropriate StringComparer. + /// The actual number of classes in the typeDict matching this StringComparer might be lower. /// public int ClassCount; @@ -287,7 +290,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation ITypeDefinition defInDict; if (dict.TryGetValue(key, out defInDict)) { if (defInDict == typeDefinition) { - wasRemoved = true; + if (dict.Comparer == FullNameAndTypeParameterCountComparer.Ordinal) { + // Set wasRemoved flag only on removal in the ordinal comparison. + // This keeps the ClassCount consistent when there are name clashes. + wasRemoved = true; + } dict.Remove(key); } } @@ -325,6 +332,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation if (typeDefinition == null) throw new ArgumentNullException("typeDefinition"); var key = new FullNameAndTypeParameterCount(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameterCount); + // Set isNew on addition in the ordinal comparison. + // This keeps the ClassCount consistent when there are name clashes. bool isNew = !_typeDicts[0].ContainsKey(key); foreach (var dict in _typeDicts) { dict[key] = typeDefinition;