/* Copyright (C) 2011 de4dot@gmail.com This file is part of de4dot. de4dot is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. de4dot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with de4dot. If not, see . */ using System.Collections.Generic; using Mono.Cecil; using de4dot.blocks; namespace de4dot.code.renamer.asmmodules { interface RefDict where TRef : Ref where TMRef : MemberReference { int Count { get; } IEnumerable getAll(); IEnumerable getSorted(); TRef find(TMRef tmref); void add(TRef tref); void onTypesRenamed(); } class TypeDefDict : RefDict { TypeDefinitionDict typeToDef = new TypeDefinitionDict(); public int Count { get { return typeToDef.Count; } } public IEnumerable getAll() { return typeToDef.getAll(); } public IEnumerable getSorted() { var list = new List(getAll()); list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index)); return list; } public TypeDef find(TypeReference typeReference) { return typeToDef.find(typeReference); } public void add(TypeDef typeDef) { typeToDef.add(typeDef.TypeDefinition, typeDef); } public void onTypesRenamed() { typeToDef.onTypesRenamed(); } } class FieldDefDict : RefDict { FieldDefinitionDict fieldToDef = new FieldDefinitionDict(); public int Count { get { return fieldToDef.Count; } } public IEnumerable getAll() { return fieldToDef.getAll(); } public IEnumerable getSorted() { var list = new List(getAll()); list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index)); return list; } public FieldDef find(FieldReference fieldReference) { return fieldToDef.find(fieldReference); } public void add(FieldDef fieldDef) { fieldToDef.add(fieldDef.FieldDefinition, fieldDef); } public void onTypesRenamed() { fieldToDef.onTypesRenamed(); } } class MethodDefDict : RefDict { MethodDefinitionDict methodToDef = new MethodDefinitionDict(); public int Count { get { return methodToDef.Count; } } public IEnumerable getAll() { return methodToDef.getAll(); } public IEnumerable getSorted() { var list = new List(getAll()); list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index)); return list; } public MethodDef find(MethodReference methodReference) { return methodToDef.find(methodReference); } public void add(MethodDef methodDef) { methodToDef.add(methodDef.MethodDefinition, methodDef); } public void onTypesRenamed() { methodToDef.onTypesRenamed(); } } class PropertyDefDict : RefDict { PropertyDefinitionDict propToDef = new PropertyDefinitionDict(); public int Count { get { return propToDef.Count; } } public IEnumerable getAll() { return propToDef.getAll(); } public IEnumerable getSorted() { var list = new List(getAll()); list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index)); return list; } public PropertyDef find(PropertyReference propertyReference) { return propToDef.find(propertyReference); } public void add(PropertyDef propDef) { propToDef.add(propDef.PropertyDefinition, propDef); } public void onTypesRenamed() { propToDef.onTypesRenamed(); } } class EventDefDict : RefDict { EventDefinitionDict eventToDef = new EventDefinitionDict(); public int Count { get { return eventToDef.Count; } } public IEnumerable getAll() { return eventToDef.getAll(); } public IEnumerable getSorted() { var list = new List(getAll()); list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index)); return list; } public EventDef find(EventReference eventReference) { return eventToDef.find(eventReference); } public void add(EventDef eventDef) { eventToDef.add(eventDef.EventDefinition, eventDef); } public void onTypesRenamed() { eventToDef.onTypesRenamed(); } } }