de4dot-cex/de4dot.code/renamer/asmmodules/RefDict.cs

184 lines
4.7 KiB
C#
Raw Normal View History

2011-11-15 21:26:51 +08:00
/*
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 <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
using Mono.Cecil;
using de4dot.blocks;
namespace de4dot.code.renamer.asmmodules {
2011-11-15 21:26:51 +08:00
interface RefDict<TRef, TMRef> where TRef : Ref where TMRef : MemberReference {
2011-11-21 17:36:23 +08:00
int Count { get; }
2011-11-15 21:26:51 +08:00
IEnumerable<TRef> getAll();
IEnumerable<TRef> getSorted();
TRef find(TMRef tmref);
void add(TRef tref);
void onTypesRenamed();
}
class TypeDefDict : RefDict<TypeDef, TypeReference> {
TypeDefinitionDict<TypeDef> typeToDef = new TypeDefinitionDict<TypeDef>();
2011-11-15 21:26:51 +08:00
2011-11-21 17:36:23 +08:00
public int Count {
get { return typeToDef.Count; }
2011-11-21 17:36:23 +08:00
}
2011-11-15 21:26:51 +08:00
public IEnumerable<TypeDef> getAll() {
return typeToDef.getAll();
2011-11-15 21:26:51 +08:00
}
public IEnumerable<TypeDef> getSorted() {
var list = new List<TypeDef>(getAll());
2011-11-21 17:36:23 +08:00
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
2011-11-15 21:26:51 +08:00
return list;
}
public TypeDef find(TypeReference typeReference) {
return typeToDef.find(typeReference);
2011-11-15 21:26:51 +08:00
}
public void add(TypeDef typeDef) {
typeToDef.add(typeDef.TypeDefinition, typeDef);
2011-11-15 21:26:51 +08:00
}
public void onTypesRenamed() {
typeToDef.onTypesRenamed();
2011-11-15 21:26:51 +08:00
}
}
class FieldDefDict : RefDict<FieldDef, FieldReference> {
FieldDefinitionDict<FieldDef> fieldToDef = new FieldDefinitionDict<FieldDef>();
2011-11-15 21:26:51 +08:00
2011-11-21 17:36:23 +08:00
public int Count {
get { return fieldToDef.Count; }
2011-11-21 17:36:23 +08:00
}
2011-11-15 21:26:51 +08:00
public IEnumerable<FieldDef> getAll() {
return fieldToDef.getAll();
2011-11-15 21:26:51 +08:00
}
public IEnumerable<FieldDef> getSorted() {
var list = new List<FieldDef>(getAll());
2011-11-21 17:36:23 +08:00
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
2011-11-15 21:26:51 +08:00
return list;
}
public FieldDef find(FieldReference fieldReference) {
return fieldToDef.find(fieldReference);
2011-11-15 21:26:51 +08:00
}
public void add(FieldDef fieldDef) {
fieldToDef.add(fieldDef.FieldDefinition, fieldDef);
2011-11-15 21:26:51 +08:00
}
public void onTypesRenamed() {
fieldToDef.onTypesRenamed();
2011-11-15 21:26:51 +08:00
}
}
class MethodDefDict : RefDict<MethodDef, MethodReference> {
MethodDefinitionDict<MethodDef> methodToDef = new MethodDefinitionDict<MethodDef>();
2011-11-15 21:26:51 +08:00
2011-11-21 17:36:23 +08:00
public int Count {
get { return methodToDef.Count; }
2011-11-21 17:36:23 +08:00
}
2011-11-15 21:26:51 +08:00
public IEnumerable<MethodDef> getAll() {
return methodToDef.getAll();
2011-11-15 21:26:51 +08:00
}
public IEnumerable<MethodDef> getSorted() {
var list = new List<MethodDef>(getAll());
2011-11-21 17:36:23 +08:00
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
2011-11-15 21:26:51 +08:00
return list;
}
public MethodDef find(MethodReference methodReference) {
return methodToDef.find(methodReference);
2011-11-15 21:26:51 +08:00
}
public void add(MethodDef methodDef) {
methodToDef.add(methodDef.MethodDefinition, methodDef);
2011-11-15 21:26:51 +08:00
}
public void onTypesRenamed() {
methodToDef.onTypesRenamed();
2011-11-15 21:26:51 +08:00
}
}
class PropertyDefDict : RefDict<PropertyDef, PropertyReference> {
PropertyDefinitionDict<PropertyDef> propToDef = new PropertyDefinitionDict<PropertyDef>();
2011-11-21 17:36:23 +08:00
public int Count {
get { return propToDef.Count; }
2011-11-21 17:36:23 +08:00
}
2011-11-15 21:26:51 +08:00
public IEnumerable<PropertyDef> getAll() {
return propToDef.getAll();
2011-11-15 21:26:51 +08:00
}
public IEnumerable<PropertyDef> getSorted() {
var list = new List<PropertyDef>(getAll());
2011-11-21 17:36:23 +08:00
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
2011-11-15 21:26:51 +08:00
return list;
}
public PropertyDef find(PropertyReference propertyReference) {
return propToDef.find(propertyReference);
2011-11-15 21:26:51 +08:00
}
public void add(PropertyDef propDef) {
propToDef.add(propDef.PropertyDefinition, propDef);
2011-11-15 21:26:51 +08:00
}
public void onTypesRenamed() {
propToDef.onTypesRenamed();
2011-11-15 21:26:51 +08:00
}
}
class EventDefDict : RefDict<EventDef, EventReference> {
EventDefinitionDict<EventDef> eventToDef = new EventDefinitionDict<EventDef>();
2011-11-21 17:36:23 +08:00
public int Count {
get { return eventToDef.Count; }
2011-11-21 17:36:23 +08:00
}
2011-11-15 21:26:51 +08:00
public IEnumerable<EventDef> getAll() {
return eventToDef.getAll();
2011-11-15 21:26:51 +08:00
}
public IEnumerable<EventDef> getSorted() {
var list = new List<EventDef>(getAll());
2011-11-21 17:36:23 +08:00
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
2011-11-15 21:26:51 +08:00
return list;
}
public EventDef find(EventReference eventReference) {
return eventToDef.find(eventReference);
2011-11-15 21:26:51 +08:00
}
public void add(EventDef eventDef) {
eventToDef.add(eventDef.EventDefinition, eventDef);
2011-11-15 21:26:51 +08:00
}
public void onTypesRenamed() {
eventToDef.onTypesRenamed();
2011-11-15 21:26:51 +08:00
}
}
}