From f30b0ef74926be97d0b33dfbd678eaaebdcb36f3 Mon Sep 17 00:00:00 2001 From: de4dot Date: Fri, 16 Dec 2011 18:46:30 +0100 Subject: [PATCH] Add type, method, field, prop, event dictionaries --- AssemblyData/methodsrewriter/MModule.cs | 8 +- AssemblyData/methodsrewriter/MType.cs | 20 +- blocks/DotNetUtils.cs | 12 +- blocks/MemberReferenceHelper.cs | 336 +++++++++++++++++++++- de4dot.code/renamer/asmmodules/RefDict.cs | 110 ++----- 5 files changed, 375 insertions(+), 111 deletions(-) diff --git a/AssemblyData/methodsrewriter/MModule.cs b/AssemblyData/methodsrewriter/MModule.cs index f02f34a2..d93907fc 100644 --- a/AssemblyData/methodsrewriter/MModule.cs +++ b/AssemblyData/methodsrewriter/MModule.cs @@ -27,7 +27,7 @@ namespace AssemblyData.methodsrewriter { class MModule { public Module module; public ModuleDefinition moduleDefinition; - Dictionary typeReferenceToType = new Dictionary(); + TypeDefinitionDict typeReferenceToType = new TypeDefinitionDict(); Dictionary tokenToType = new Dictionary(); Dictionary tokenToGlobalMethod; Dictionary tokenToGlobalField; @@ -52,14 +52,12 @@ namespace AssemblyData.methodsrewriter { foreach (var token in tmpTokenToType.Keys) { var mtype = new MType(tmpTokenToType[token], tmpTokenToTypeDefinition[token]); tokenToType[token] = mtype; - typeReferenceToType[new TypeReferenceKey(mtype.typeDefinition)] = mtype; + typeReferenceToType.add(mtype.typeDefinition, mtype); } } public MType getType(TypeReference typeReference) { - MType type; - typeReferenceToType.TryGetValue(new TypeReferenceKey(typeReference), out type); - return type; + return typeReferenceToType.find(typeReference); } public MMethod getMethod(MethodReference methodReference) { diff --git a/AssemblyData/methodsrewriter/MType.cs b/AssemblyData/methodsrewriter/MType.cs index fa90e555..6c1bd7f3 100644 --- a/AssemblyData/methodsrewriter/MType.cs +++ b/AssemblyData/methodsrewriter/MType.cs @@ -28,9 +28,9 @@ namespace AssemblyData.methodsrewriter { public Type type; public TypeDefinition typeDefinition; Dictionary tokenToMethod; - Dictionary methodReferenceToMethod; + MethodDefinitionDict methodReferenceToMethod; Dictionary tokenToField; - Dictionary fieldReferenceToField; + FieldDefinitionDict fieldReferenceToField; public MType(Type type, TypeDefinition typeDefinition) { this.type = type; @@ -39,16 +39,12 @@ namespace AssemblyData.methodsrewriter { public MMethod getMethod(MethodReference methodReference) { initMethods(); - MMethod method; - methodReferenceToMethod.TryGetValue(new MethodReferenceKey(methodReference), out method); - return method; + return methodReferenceToMethod.find(methodReference); } public MField getField(FieldReference fieldReference) { initFields(); - MField field; - fieldReferenceToField.TryGetValue(new FieldReferenceKey(fieldReference), out field); - return field; + return fieldReferenceToField.find(fieldReference); } public MMethod getMethod(int token) { @@ -65,7 +61,7 @@ namespace AssemblyData.methodsrewriter { if (tokenToMethod != null) return; tokenToMethod = new Dictionary(typeDefinition.Methods.Count); - methodReferenceToMethod = new Dictionary(); + methodReferenceToMethod = new MethodDefinitionDict(); var tmpTokenToMethod = new Dictionary(); var flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; @@ -75,7 +71,7 @@ namespace AssemblyData.methodsrewriter { var token = m.MetadataToken.ToInt32(); var method = new MMethod(tmpTokenToMethod[token], m); tokenToMethod[token] = method; - methodReferenceToMethod[new MethodReferenceKey(method.methodDefinition)] = method; + methodReferenceToMethod.add(method.methodDefinition, method); } } @@ -83,7 +79,7 @@ namespace AssemblyData.methodsrewriter { if (tokenToField != null) return; tokenToField = new Dictionary(typeDefinition.Fields.Count); - fieldReferenceToField = new Dictionary(); + fieldReferenceToField = new FieldDefinitionDict(); var tmpTokenToField = new Dictionary(); var flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; @@ -93,7 +89,7 @@ namespace AssemblyData.methodsrewriter { var token = f.MetadataToken.ToInt32(); var field = new MField(tmpTokenToField[token], f); tokenToField[token] = field; - fieldReferenceToField[new FieldReferenceKey(field.fieldDefinition)] = field; + fieldReferenceToField.add(field.fieldDefinition, field); } } diff --git a/blocks/DotNetUtils.cs b/blocks/DotNetUtils.cs index 02841723..74372a7e 100644 --- a/blocks/DotNetUtils.cs +++ b/blocks/DotNetUtils.cs @@ -25,7 +25,7 @@ using Mono.Cecil.Cil; namespace de4dot.blocks { class TypeCache { ModuleDefinition module; - Dictionary typeRefToDef = new Dictionary(); + TypeDefinitionDict typeRefToDef = new TypeDefinitionDict(); public TypeCache(ModuleDefinition module) { this.module = module; @@ -33,16 +33,12 @@ namespace de4dot.blocks { } void init() { - foreach (var type in module.GetTypes()) { - var key = new TypeReferenceKey(type); - typeRefToDef[key] = type; - } + foreach (var type in module.GetTypes()) + typeRefToDef.add(type, type); } public TypeDefinition lookup(TypeReference typeReference) { - TypeDefinition typeDefinition; - typeRefToDef.TryGetValue(new TypeReferenceKey(typeReference), out typeDefinition); - return typeDefinition; + return typeRefToDef.find(typeReference); } } diff --git a/blocks/MemberReferenceHelper.cs b/blocks/MemberReferenceHelper.cs index 6f2b25be..1cd8aea4 100644 --- a/blocks/MemberReferenceHelper.cs +++ b/blocks/MemberReferenceHelper.cs @@ -44,6 +44,256 @@ namespace de4dot.blocks { TypeReference, } + public class TypeDefinitionDict { + Dictionary tokenToValue = new Dictionary(); + Dictionary refToValue = new Dictionary(); + + public int Count { + get { return tokenToValue.Count; } + } + + public IEnumerable getAll() { + return tokenToValue.Values; + } + + ScopeAndTokenKey getTokenKey(TypeReference typeReference) { + return new ScopeAndTokenKey(typeReference); + } + + TypeReferenceKey getReferenceKey(TypeReference typeReference) { + return new TypeReferenceKey(typeReference); + } + + public TValue find(TypeReference typeReference) { + TValue value; + if (tokenToValue.TryGetValue(getTokenKey(typeReference), out value)) + return value; + + refToValue.TryGetValue(getReferenceKey(typeReference), out value); + return value; + } + + public void add(TypeDefinition typeDefinition, TValue value) { + tokenToValue[getTokenKey(typeDefinition)] = value; + refToValue[getReferenceKey(typeDefinition)] = value; + } + + public void onTypesRenamed() { + var newTypeRefToValue = new Dictionary(refToValue.Count); + foreach (var kvp in refToValue) + newTypeRefToValue[getReferenceKey((TypeDefinition)kvp.Key.TypeReference)] = kvp.Value; + refToValue = newTypeRefToValue; + } + } + + public abstract class FieldDefinitionDictBase { + Dictionary tokenToValue = new Dictionary(); + Dictionary refToValue = new Dictionary(); + + public int Count { + get { return tokenToValue.Count; } + } + + public IEnumerable getAll() { + return tokenToValue.Values; + } + + ScopeAndTokenKey getTokenKey(FieldReference fieldReference) { + return new ScopeAndTokenKey(fieldReference); + } + + protected abstract IFieldReferenceKey getReferenceKey(FieldReference fieldReference); + + public TValue find(FieldReference fieldReference) { + TValue value; + if (tokenToValue.TryGetValue(getTokenKey(fieldReference), out value)) + return value; + + refToValue.TryGetValue(getReferenceKey(fieldReference), out value); + return value; + } + + public void add(FieldDefinition fieldDefinition, TValue value) { + tokenToValue[getTokenKey(fieldDefinition)] = value; + refToValue[getReferenceKey(fieldDefinition)] = value; + } + + public void onTypesRenamed() { + var newFieldRefToDef = new Dictionary(refToValue.Count); + foreach (var kvp in refToValue) + newFieldRefToDef[getReferenceKey((FieldDefinition)kvp.Key.FieldReference)] = kvp.Value; + refToValue = newFieldRefToDef; + } + } + + public class FieldDefinitionDict : FieldDefinitionDictBase { + protected override IFieldReferenceKey getReferenceKey(FieldReference fieldReference) { + return new FieldReferenceKey(fieldReference); + } + } + + public class FieldDefinitionAndDeclaringTypeDict : FieldDefinitionDictBase { + protected override IFieldReferenceKey getReferenceKey(FieldReference fieldReference) { + return new FieldReferenceAndDeclaringTypeKey(fieldReference); + } + } + + public abstract class MethodDefinitionDictBase { + Dictionary tokenToValue = new Dictionary(); + Dictionary refToValue = new Dictionary(); + + public int Count { + get { return tokenToValue.Count; } + } + + public IEnumerable getAll() { + return tokenToValue.Values; + } + + ScopeAndTokenKey getTokenKey(MethodReference methodReference) { + return new ScopeAndTokenKey(methodReference); + } + + protected abstract IMethodReferenceKey getReferenceKey(MethodReference methodReference); + + public TValue find(MethodReference methodReference) { + TValue value; + if (tokenToValue.TryGetValue(getTokenKey(methodReference), out value)) + return value; + + refToValue.TryGetValue(getReferenceKey(methodReference), out value); + return value; + } + + public void add(MethodDefinition methodDefinition, TValue value) { + tokenToValue[getTokenKey(methodDefinition)] = value; + refToValue[getReferenceKey(methodDefinition)] = value; + } + + public void onTypesRenamed() { + var newFieldRefToDef = new Dictionary(refToValue.Count); + foreach (var kvp in refToValue) + newFieldRefToDef[getReferenceKey((MethodDefinition)kvp.Key.MethodReference)] = kvp.Value; + refToValue = newFieldRefToDef; + } + } + + public class MethodDefinitionDict : MethodDefinitionDictBase { + protected override IMethodReferenceKey getReferenceKey(MethodReference methodReference) { + return new MethodReferenceKey(methodReference); + } + } + + public class MethodDefinitionAndDeclaringTypeDict : MethodDefinitionDictBase { + protected override IMethodReferenceKey getReferenceKey(MethodReference methodReference) { + return new MethodReferenceAndDeclaringTypeKey(methodReference); + } + } + + public abstract class PropertyDefinitionDictBase { + Dictionary tokenToValue = new Dictionary(); + Dictionary refToValue = new Dictionary(); + + public int Count { + get { return tokenToValue.Count; } + } + + public IEnumerable getAll() { + return tokenToValue.Values; + } + + ScopeAndTokenKey getTokenKey(PropertyReference propertyReference) { + return new ScopeAndTokenKey(propertyReference); + } + + protected abstract IPropertyReferenceKey getReferenceKey(PropertyReference propertyReference); + + public TValue find(PropertyReference propertyReference) { + TValue value; + if (tokenToValue.TryGetValue(getTokenKey(propertyReference), out value)) + return value; + + refToValue.TryGetValue(getReferenceKey(propertyReference), out value); + return value; + } + + public void add(PropertyDefinition propertyDefinition, TValue value) { + tokenToValue[getTokenKey(propertyDefinition)] = value; + refToValue[getReferenceKey(propertyDefinition)] = value; + } + + public void onTypesRenamed() { + var newFieldRefToDef = new Dictionary(refToValue.Count); + foreach (var kvp in refToValue) + newFieldRefToDef[getReferenceKey((PropertyDefinition)kvp.Key.PropertyReference)] = kvp.Value; + refToValue = newFieldRefToDef; + } + } + + public class PropertyDefinitionDict : PropertyDefinitionDictBase { + protected override IPropertyReferenceKey getReferenceKey(PropertyReference propertyReference) { + return new PropertyReferenceKey(propertyReference); + } + } + + public class PropertyDefinitionAndDeclaringTypeDict : PropertyDefinitionDictBase { + protected override IPropertyReferenceKey getReferenceKey(PropertyReference propertyReference) { + return new PropertyReferenceAndDeclaringTypeKey(propertyReference); + } + } + + public abstract class EventDefinitionDictBase { + Dictionary tokenToValue = new Dictionary(); + Dictionary refToValue = new Dictionary(); + + public int Count { + get { return tokenToValue.Count; } + } + + public IEnumerable getAll() { + return tokenToValue.Values; + } + + ScopeAndTokenKey getTokenKey(EventReference eventReference) { + return new ScopeAndTokenKey(eventReference); + } + + protected abstract IEventReferenceKey getReferenceKey(EventReference eventReference); + + public TValue find(EventReference eventReference) { + TValue value; + if (tokenToValue.TryGetValue(getTokenKey(eventReference), out value)) + return value; + + refToValue.TryGetValue(getReferenceKey(eventReference), out value); + return value; + } + + public void add(EventDefinition eventDefinition, TValue value) { + tokenToValue[getTokenKey(eventDefinition)] = value; + refToValue[getReferenceKey(eventDefinition)] = value; + } + + public void onTypesRenamed() { + var newFieldRefToDef = new Dictionary(refToValue.Count); + foreach (var kvp in refToValue) + newFieldRefToDef[getReferenceKey((EventDefinition)kvp.Key.EventReference)] = kvp.Value; + refToValue = newFieldRefToDef; + } + } + + public class EventDefinitionDict : EventDefinitionDictBase { + protected override IEventReferenceKey getReferenceKey(EventReference eventReference) { + return new EventReferenceKey(eventReference); + } + } + + public class EventDefinitionAndDeclaringTypeDict : EventDefinitionDictBase { + protected override IEventReferenceKey getReferenceKey(EventReference eventReference) { + return new EventReferenceAndDeclaringTypeKey(eventReference); + } + } + public class ScopeAndTokenKey { readonly IMetadataScope scope; readonly int token; @@ -144,7 +394,23 @@ namespace de4dot.blocks { } } - public class FieldReferenceKey { + public interface IFieldReferenceKey { + FieldReference FieldReference { get; } + } + + public interface IPropertyReferenceKey { + PropertyReference PropertyReference { get; } + } + + public interface IEventReferenceKey { + EventReference EventReference { get; } + } + + public interface IMethodReferenceKey { + MethodReference MethodReference { get; } + } + + public class FieldReferenceKey : IFieldReferenceKey { readonly FieldReference fieldRef; public FieldReference FieldReference { @@ -171,7 +437,7 @@ namespace de4dot.blocks { } } - public class PropertyReferenceKey { + public class PropertyReferenceKey : IPropertyReferenceKey { readonly PropertyReference propRef; public PropertyReference PropertyReference { @@ -198,7 +464,7 @@ namespace de4dot.blocks { } } - public class EventReferenceKey { + public class EventReferenceKey : IEventReferenceKey { readonly EventReference eventRef; public EventReference EventReference { @@ -225,7 +491,7 @@ namespace de4dot.blocks { } } - public class MethodReferenceKey { + public class MethodReferenceKey : IMethodReferenceKey { readonly MethodReference methodRef; public MethodReference MethodReference { @@ -252,7 +518,7 @@ namespace de4dot.blocks { } } - public class FieldReferenceAndDeclaringTypeKey { + public class FieldReferenceAndDeclaringTypeKey : IFieldReferenceKey { readonly FieldReference fieldRef; public FieldReference FieldReference { @@ -281,7 +547,65 @@ namespace de4dot.blocks { } } - public class MethodReferenceAndDeclaringTypeKey { + public class PropertyReferenceAndDeclaringTypeKey : IPropertyReferenceKey { + readonly PropertyReference propRef; + + public PropertyReference PropertyReference { + get { return propRef; } + } + + public PropertyReferenceAndDeclaringTypeKey(PropertyReference propRef) { + this.propRef = propRef; + } + + public override int GetHashCode() { + return MemberReferenceHelper.propertyReferenceHashCode(propRef) + + MemberReferenceHelper.typeHashCode(propRef.DeclaringType); + } + + public override bool Equals(object obj) { + var other = obj as PropertyReferenceAndDeclaringTypeKey; + if (other == null) + return false; + return MemberReferenceHelper.comparePropertyReference(propRef, other.propRef) && + MemberReferenceHelper.compareTypes(propRef.DeclaringType, other.propRef.DeclaringType); + } + + public override string ToString() { + return propRef.ToString(); + } + } + + public class EventReferenceAndDeclaringTypeKey : IEventReferenceKey { + readonly EventReference eventRef; + + public EventReference EventReference { + get { return eventRef; } + } + + public EventReferenceAndDeclaringTypeKey(EventReference eventRef) { + this.eventRef = eventRef; + } + + public override int GetHashCode() { + return MemberReferenceHelper.eventReferenceHashCode(eventRef) + + MemberReferenceHelper.typeHashCode(eventRef.DeclaringType); + } + + public override bool Equals(object obj) { + var other = obj as EventReferenceAndDeclaringTypeKey; + if (other == null) + return false; + return MemberReferenceHelper.compareEventReference(eventRef, other.eventRef) && + MemberReferenceHelper.compareTypes(eventRef.DeclaringType, other.eventRef.DeclaringType); + } + + public override string ToString() { + return eventRef.ToString(); + } + } + + public class MethodReferenceAndDeclaringTypeKey : IMethodReferenceKey { readonly MethodReference methodRef; public MethodReference MethodReference { diff --git a/de4dot.code/renamer/asmmodules/RefDict.cs b/de4dot.code/renamer/asmmodules/RefDict.cs index 2efc3381..238856b6 100644 --- a/de4dot.code/renamer/asmmodules/RefDict.cs +++ b/de4dot.code/renamer/asmmodules/RefDict.cs @@ -32,15 +32,14 @@ namespace de4dot.code.renamer.asmmodules { } class TypeDefDict : RefDict { - Dictionary tokenToTypeDef = new Dictionary(); - Dictionary typeRefToDef = new Dictionary(); + TypeDefinitionDict typeToDef = new TypeDefinitionDict(); public int Count { - get { return tokenToTypeDef.Count; } + get { return typeToDef.Count; } } public IEnumerable getAll() { - return tokenToTypeDef.Values; + return typeToDef.getAll(); } public IEnumerable getSorted() { @@ -50,37 +49,27 @@ namespace de4dot.code.renamer.asmmodules { } public TypeDef find(TypeReference typeReference) { - TypeDef typeDef; - if (tokenToTypeDef.TryGetValue(new ScopeAndTokenKey(typeReference), out typeDef)) - return typeDef; - - typeRefToDef.TryGetValue(new TypeReferenceKey(typeReference), out typeDef); - return typeDef; + return typeToDef.find(typeReference); } public void add(TypeDef typeDef) { - tokenToTypeDef[new ScopeAndTokenKey(typeDef.TypeDefinition)] = typeDef; - typeRefToDef[new TypeReferenceKey(typeDef.TypeDefinition)] = typeDef; + typeToDef.add(typeDef.TypeDefinition, typeDef); } public void onTypesRenamed() { - var all = new List(typeRefToDef.Values); - typeRefToDef.Clear(); - foreach (var typeDef in all) - typeRefToDef[new TypeReferenceKey(typeDef.TypeDefinition)] = typeDef; + typeToDef.onTypesRenamed(); } } class FieldDefDict : RefDict { - Dictionary tokenToFieldDef = new Dictionary(); - Dictionary fieldRefToDef = new Dictionary(); + FieldDefinitionDict fieldToDef = new FieldDefinitionDict(); public int Count { - get { return tokenToFieldDef.Count; } + get { return fieldToDef.Count; } } public IEnumerable getAll() { - return tokenToFieldDef.Values; + return fieldToDef.getAll(); } public IEnumerable getSorted() { @@ -90,37 +79,27 @@ namespace de4dot.code.renamer.asmmodules { } public FieldDef find(FieldReference fieldReference) { - FieldDef fieldDef; - if (tokenToFieldDef.TryGetValue(new ScopeAndTokenKey(fieldReference), out fieldDef)) - return fieldDef; - - fieldRefToDef.TryGetValue(new FieldReferenceKey(fieldReference), out fieldDef); - return fieldDef; + return fieldToDef.find(fieldReference); } public void add(FieldDef fieldDef) { - tokenToFieldDef[new ScopeAndTokenKey(fieldDef.FieldDefinition)] = fieldDef; - fieldRefToDef[new FieldReferenceKey(fieldDef.FieldDefinition)] = fieldDef; + fieldToDef.add(fieldDef.FieldDefinition, fieldDef); } public void onTypesRenamed() { - var all = new List(fieldRefToDef.Values); - fieldRefToDef.Clear(); - foreach (var fieldDef in all) - fieldRefToDef[new FieldReferenceKey(fieldDef.FieldDefinition)] = fieldDef; + fieldToDef.onTypesRenamed(); } } class MethodDefDict : RefDict { - Dictionary tokenToMethodDef = new Dictionary(); - Dictionary methodRefToDef = new Dictionary(); + MethodDefinitionDict methodToDef = new MethodDefinitionDict(); public int Count { - get { return tokenToMethodDef.Count; } + get { return methodToDef.Count; } } public IEnumerable getAll() { - return tokenToMethodDef.Values; + return methodToDef.getAll(); } public IEnumerable getSorted() { @@ -130,37 +109,27 @@ namespace de4dot.code.renamer.asmmodules { } public MethodDef find(MethodReference methodReference) { - MethodDef methodDef; - if (tokenToMethodDef.TryGetValue(new ScopeAndTokenKey(methodReference), out methodDef)) - return methodDef; - - methodRefToDef.TryGetValue(new MethodReferenceKey(methodReference), out methodDef); - return methodDef; + return methodToDef.find(methodReference); } public void add(MethodDef methodDef) { - tokenToMethodDef[new ScopeAndTokenKey(methodDef.MethodDefinition)] = methodDef; - methodRefToDef[new MethodReferenceKey(methodDef.MethodDefinition)] = methodDef; + methodToDef.add(methodDef.MethodDefinition, methodDef); } public void onTypesRenamed() { - var all = new List(methodRefToDef.Values); - methodRefToDef.Clear(); - foreach (var methodDef in all) - methodRefToDef[new MethodReferenceKey(methodDef.MethodDefinition)] = methodDef; + methodToDef.onTypesRenamed(); } } class PropertyDefDict : RefDict { - Dictionary tokenToPropDef = new Dictionary(); - Dictionary propRefToDef = new Dictionary(); + PropertyDefinitionDict propToDef = new PropertyDefinitionDict(); public int Count { - get { return tokenToPropDef.Count; } + get { return propToDef.Count; } } public IEnumerable getAll() { - return tokenToPropDef.Values; + return propToDef.getAll(); } public IEnumerable getSorted() { @@ -170,37 +139,27 @@ namespace de4dot.code.renamer.asmmodules { } public PropertyDef find(PropertyReference propertyReference) { - PropertyDef propDef; - if (tokenToPropDef.TryGetValue(new ScopeAndTokenKey(propertyReference), out propDef)) - return propDef; - - propRefToDef.TryGetValue(new PropertyReferenceKey(propertyReference), out propDef); - return propDef; + return propToDef.find(propertyReference); } public void add(PropertyDef propDef) { - tokenToPropDef[new ScopeAndTokenKey(propDef.PropertyDefinition)] = propDef; - propRefToDef[new PropertyReferenceKey(propDef.PropertyDefinition)] = propDef; + propToDef.add(propDef.PropertyDefinition, propDef); } public void onTypesRenamed() { - var all = new List(propRefToDef.Values); - propRefToDef.Clear(); - foreach (var propDef in all) - propRefToDef[new PropertyReferenceKey(propDef.PropertyDefinition)] = propDef; + propToDef.onTypesRenamed(); } } class EventDefDict : RefDict { - Dictionary tokenToEventDef = new Dictionary(); - Dictionary eventRefToDef = new Dictionary(); + EventDefinitionDict eventToDef = new EventDefinitionDict(); public int Count { - get { return tokenToEventDef.Count; } + get { return eventToDef.Count; } } public IEnumerable getAll() { - return tokenToEventDef.Values; + return eventToDef.getAll(); } public IEnumerable getSorted() { @@ -210,24 +169,15 @@ namespace de4dot.code.renamer.asmmodules { } public EventDef find(EventReference eventReference) { - EventDef eventDef; - if (tokenToEventDef.TryGetValue(new ScopeAndTokenKey(eventReference), out eventDef)) - return eventDef; - - eventRefToDef.TryGetValue(new EventReferenceKey(eventReference), out eventDef); - return eventDef; + return eventToDef.find(eventReference); } public void add(EventDef eventDef) { - tokenToEventDef[new ScopeAndTokenKey(eventDef.EventDefinition)] = eventDef; - eventRefToDef[new EventReferenceKey(eventDef.EventDefinition)] = eventDef; + eventToDef.add(eventDef.EventDefinition, eventDef); } public void onTypesRenamed() { - var all = new List(eventRefToDef.Values); - eventRefToDef.Clear(); - foreach (var eventDef in all) - eventRefToDef[new EventReferenceKey(eventDef.EventDefinition)] = eventDef; + eventToDef.onTypesRenamed(); } } }