From dd8d0d0e83f7a68ad60047f29eb2b55d2fc1063c Mon Sep 17 00:00:00 2001 From: de4dot Date: Fri, 16 Dec 2011 19:33:44 +0100 Subject: [PATCH] Use new method/field dictionaries --- de4dot.code/renamer/TypeInfo.cs | 46 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/de4dot.code/renamer/TypeInfo.cs b/de4dot.code/renamer/TypeInfo.cs index 455602ea..3a4a5d23 100644 --- a/de4dot.code/renamer/TypeInfo.cs +++ b/de4dot.code/renamer/TypeInfo.cs @@ -415,12 +415,12 @@ namespace de4dot.code.renamer { void initializeWindowsFormsFieldsAndProps() { var checker = NameChecker; - var ourFields = new Dictionary(); + var ourFields = new FieldDefinitionAndDeclaringTypeDict(); foreach (var fieldDef in type.AllFields) - ourFields[new FieldReferenceAndDeclaringTypeKey(fieldDef.FieldDefinition)] = fieldDef; - var ourMethods = new Dictionary(); + ourFields.add(fieldDef.FieldDefinition, fieldDef); + var ourMethods = new MethodDefinitionAndDeclaringTypeDict(); foreach (var methodDef in type.AllMethods) - ourMethods[new MethodReferenceAndDeclaringTypeKey(methodDef.MethodDefinition)] = methodDef; + ourMethods.add(methodDef.MethodDefinition, methodDef); foreach (var methodDef in type.AllMethods) { if (methodDef.MethodDefinition.Body == null) @@ -448,8 +448,8 @@ namespace de4dot.code.renamer { var calledMethod = instr.Operand as MethodReference; if (calledMethod == null) continue; - MethodDef calledMethodDef; - if (!ourMethods.TryGetValue(new MethodReferenceAndDeclaringTypeKey(calledMethod), out calledMethodDef)) + var calledMethodDef = ourMethods.find(calledMethod); + if (calledMethodDef == null) continue; fieldRef = getFieldReference(calledMethodDef.MethodDefinition); if (fieldRef == null) @@ -468,8 +468,8 @@ namespace de4dot.code.renamer { if (fieldRef == null) continue; - FieldDef fieldDef; - if (!ourFields.TryGetValue(new FieldReferenceAndDeclaringTypeKey(fieldRef), out fieldDef)) + var fieldDef = ourFields.find(fieldRef); + if (fieldDef == null) continue; var fieldInfo = memberInfos.field(fieldDef); @@ -499,12 +499,12 @@ namespace de4dot.code.renamer { } public void initializeEventHandlerNames() { - var ourFields = new Dictionary(); + var ourFields = new FieldDefinitionAndDeclaringTypeDict(); foreach (var fieldDef in type.AllFields) - ourFields[new FieldReferenceAndDeclaringTypeKey(fieldDef.FieldDefinition)] = fieldDef; - var ourMethods = new Dictionary(); + ourFields.add(fieldDef.FieldDefinition, fieldDef); + var ourMethods = new MethodDefinitionAndDeclaringTypeDict(); foreach (var methodDef in type.AllMethods) - ourMethods[new MethodReferenceAndDeclaringTypeKey(methodDef.MethodDefinition)] = methodDef; + ourMethods.add(methodDef.MethodDefinition, methodDef); initVbEventHandlers(ourFields, ourMethods); initFieldEventHandlers(ourFields, ourMethods); @@ -513,7 +513,7 @@ namespace de4dot.code.renamer { // VB initializes the handlers in the property setter, where it first removes the handler // from the previous control, and then adds the handler to the new control. - void initVbEventHandlers(Dictionary ourFields, Dictionary ourMethods) { + void initVbEventHandlers(FieldDefinitionAndDeclaringTypeDict ourFields, MethodDefinitionAndDeclaringTypeDict ourMethods) { var checker = NameChecker; foreach (var propDef in type.AllProperties) { @@ -528,8 +528,8 @@ namespace de4dot.code.renamer { var handler = getVbHandler(setterDef.MethodDefinition, out eventName); if (handler == null) continue; - MethodDef handlerDef; - if (!ourMethods.TryGetValue(new MethodReferenceAndDeclaringTypeKey(handler), out handlerDef)) + var handlerDef = ourMethods.find(handler); + if (handlerDef == null) continue; if (!checker.isValidEventName(eventName)) @@ -630,7 +630,7 @@ namespace de4dot.code.renamer { return -1; } - void initFieldEventHandlers(Dictionary ourFields, Dictionary ourMethods) { + void initFieldEventHandlers(FieldDefinitionAndDeclaringTypeDict ourFields, MethodDefinitionAndDeclaringTypeDict ourMethods) { var checker = NameChecker; foreach (var methodDef in type.AllMethods) { @@ -658,8 +658,8 @@ namespace de4dot.code.renamer { var fieldRef = ldfld.Operand as FieldReference; if (fieldRef == null) continue; - FieldDef fieldDef; - if (!ourFields.TryGetValue(new FieldReferenceAndDeclaringTypeKey(fieldRef), out fieldDef)) + var fieldDef = ourFields.find(fieldRef); + if (fieldDef == null) continue; if (DotNetUtils.getArgIndex(methodDef.MethodDefinition, instructions[index++]) != 0) @@ -681,8 +681,8 @@ namespace de4dot.code.renamer { } if (methodRef == null) continue; - MethodDef handlerMethod; - if (!ourMethods.TryGetValue(new MethodReferenceAndDeclaringTypeKey(methodRef), out handlerMethod)) + var handlerMethod = ourMethods.find(methodRef); + if (handlerMethod == null) continue; var newobj = instructions[index++]; @@ -709,7 +709,7 @@ namespace de4dot.code.renamer { } } - void initTypeEventHandlers(Dictionary ourFields, Dictionary ourMethods) { + void initTypeEventHandlers(FieldDefinitionAndDeclaringTypeDict ourFields, MethodDefinitionAndDeclaringTypeDict ourMethods) { var checker = NameChecker; foreach (var methodDef in type.AllMethods) { @@ -747,8 +747,8 @@ namespace de4dot.code.renamer { } if (handler == null) continue; - MethodDef handlerDef; - if (!ourMethods.TryGetValue(new MethodReferenceAndDeclaringTypeKey(handler), out handlerDef)) + var handlerDef = ourMethods.find(handler); + if (handlerDef == null) continue; var newobj = instructions[index++];