Add type, method, field, prop, event dictionaries

This commit is contained in:
de4dot 2011-12-16 18:46:30 +01:00
parent ca2a756a0e
commit f30b0ef749
5 changed files with 375 additions and 111 deletions

View File

@ -27,7 +27,7 @@ namespace AssemblyData.methodsrewriter {
class MModule {
public Module module;
public ModuleDefinition moduleDefinition;
Dictionary<TypeReferenceKey, MType> typeReferenceToType = new Dictionary<TypeReferenceKey, MType>();
TypeDefinitionDict<MType> typeReferenceToType = new TypeDefinitionDict<MType>();
Dictionary<int, MType> tokenToType = new Dictionary<int, MType>();
Dictionary<int, MMethod> tokenToGlobalMethod;
Dictionary<int, MField> 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) {

View File

@ -28,9 +28,9 @@ namespace AssemblyData.methodsrewriter {
public Type type;
public TypeDefinition typeDefinition;
Dictionary<int, MMethod> tokenToMethod;
Dictionary<MethodReferenceKey, MMethod> methodReferenceToMethod;
MethodDefinitionDict<MMethod> methodReferenceToMethod;
Dictionary<int, MField> tokenToField;
Dictionary<FieldReferenceKey, MField> fieldReferenceToField;
FieldDefinitionDict<MField> 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<int, MMethod>(typeDefinition.Methods.Count);
methodReferenceToMethod = new Dictionary<MethodReferenceKey, MMethod>();
methodReferenceToMethod = new MethodDefinitionDict<MMethod>();
var tmpTokenToMethod = new Dictionary<int, MethodBase>();
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<int, MField>(typeDefinition.Fields.Count);
fieldReferenceToField = new Dictionary<FieldReferenceKey, MField>();
fieldReferenceToField = new FieldDefinitionDict<MField>();
var tmpTokenToField = new Dictionary<int, FieldInfo>();
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);
}
}

View File

@ -25,7 +25,7 @@ using Mono.Cecil.Cil;
namespace de4dot.blocks {
class TypeCache {
ModuleDefinition module;
Dictionary<TypeReferenceKey, TypeDefinition> typeRefToDef = new Dictionary<TypeReferenceKey, TypeDefinition>();
TypeDefinitionDict<TypeDefinition> typeRefToDef = new TypeDefinitionDict<TypeDefinition>();
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);
}
}

View File

@ -44,6 +44,256 @@ namespace de4dot.blocks {
TypeReference,
}
public class TypeDefinitionDict<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<TypeReferenceKey, TValue> refToValue = new Dictionary<TypeReferenceKey, TValue>();
public int Count {
get { return tokenToValue.Count; }
}
public IEnumerable<TValue> 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<TypeReferenceKey, TValue>(refToValue.Count);
foreach (var kvp in refToValue)
newTypeRefToValue[getReferenceKey((TypeDefinition)kvp.Key.TypeReference)] = kvp.Value;
refToValue = newTypeRefToValue;
}
}
public abstract class FieldDefinitionDictBase<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<IFieldReferenceKey, TValue> refToValue = new Dictionary<IFieldReferenceKey, TValue>();
public int Count {
get { return tokenToValue.Count; }
}
public IEnumerable<TValue> 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<IFieldReferenceKey, TValue>(refToValue.Count);
foreach (var kvp in refToValue)
newFieldRefToDef[getReferenceKey((FieldDefinition)kvp.Key.FieldReference)] = kvp.Value;
refToValue = newFieldRefToDef;
}
}
public class FieldDefinitionDict<TValue> : FieldDefinitionDictBase<TValue> {
protected override IFieldReferenceKey getReferenceKey(FieldReference fieldReference) {
return new FieldReferenceKey(fieldReference);
}
}
public class FieldDefinitionAndDeclaringTypeDict<TValue> : FieldDefinitionDictBase<TValue> {
protected override IFieldReferenceKey getReferenceKey(FieldReference fieldReference) {
return new FieldReferenceAndDeclaringTypeKey(fieldReference);
}
}
public abstract class MethodDefinitionDictBase<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<IMethodReferenceKey, TValue> refToValue = new Dictionary<IMethodReferenceKey, TValue>();
public int Count {
get { return tokenToValue.Count; }
}
public IEnumerable<TValue> 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<IMethodReferenceKey, TValue>(refToValue.Count);
foreach (var kvp in refToValue)
newFieldRefToDef[getReferenceKey((MethodDefinition)kvp.Key.MethodReference)] = kvp.Value;
refToValue = newFieldRefToDef;
}
}
public class MethodDefinitionDict<TValue> : MethodDefinitionDictBase<TValue> {
protected override IMethodReferenceKey getReferenceKey(MethodReference methodReference) {
return new MethodReferenceKey(methodReference);
}
}
public class MethodDefinitionAndDeclaringTypeDict<TValue> : MethodDefinitionDictBase<TValue> {
protected override IMethodReferenceKey getReferenceKey(MethodReference methodReference) {
return new MethodReferenceAndDeclaringTypeKey(methodReference);
}
}
public abstract class PropertyDefinitionDictBase<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<IPropertyReferenceKey, TValue> refToValue = new Dictionary<IPropertyReferenceKey, TValue>();
public int Count {
get { return tokenToValue.Count; }
}
public IEnumerable<TValue> 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<IPropertyReferenceKey, TValue>(refToValue.Count);
foreach (var kvp in refToValue)
newFieldRefToDef[getReferenceKey((PropertyDefinition)kvp.Key.PropertyReference)] = kvp.Value;
refToValue = newFieldRefToDef;
}
}
public class PropertyDefinitionDict<TValue> : PropertyDefinitionDictBase<TValue> {
protected override IPropertyReferenceKey getReferenceKey(PropertyReference propertyReference) {
return new PropertyReferenceKey(propertyReference);
}
}
public class PropertyDefinitionAndDeclaringTypeDict<TValue> : PropertyDefinitionDictBase<TValue> {
protected override IPropertyReferenceKey getReferenceKey(PropertyReference propertyReference) {
return new PropertyReferenceAndDeclaringTypeKey(propertyReference);
}
}
public abstract class EventDefinitionDictBase<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<IEventReferenceKey, TValue> refToValue = new Dictionary<IEventReferenceKey, TValue>();
public int Count {
get { return tokenToValue.Count; }
}
public IEnumerable<TValue> 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<IEventReferenceKey, TValue>(refToValue.Count);
foreach (var kvp in refToValue)
newFieldRefToDef[getReferenceKey((EventDefinition)kvp.Key.EventReference)] = kvp.Value;
refToValue = newFieldRefToDef;
}
}
public class EventDefinitionDict<TValue> : EventDefinitionDictBase<TValue> {
protected override IEventReferenceKey getReferenceKey(EventReference eventReference) {
return new EventReferenceKey(eventReference);
}
}
public class EventDefinitionAndDeclaringTypeDict<TValue> : EventDefinitionDictBase<TValue> {
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 {

View File

@ -32,15 +32,14 @@ namespace de4dot.code.renamer.asmmodules {
}
class TypeDefDict : RefDict<TypeDef, TypeReference> {
Dictionary<ScopeAndTokenKey, TypeDef> tokenToTypeDef = new Dictionary<ScopeAndTokenKey, TypeDef>();
Dictionary<TypeReferenceKey, TypeDef> typeRefToDef = new Dictionary<TypeReferenceKey, TypeDef>();
TypeDefinitionDict<TypeDef> typeToDef = new TypeDefinitionDict<TypeDef>();
public int Count {
get { return tokenToTypeDef.Count; }
get { return typeToDef.Count; }
}
public IEnumerable<TypeDef> getAll() {
return tokenToTypeDef.Values;
return typeToDef.getAll();
}
public IEnumerable<TypeDef> 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<TypeDef>(typeRefToDef.Values);
typeRefToDef.Clear();
foreach (var typeDef in all)
typeRefToDef[new TypeReferenceKey(typeDef.TypeDefinition)] = typeDef;
typeToDef.onTypesRenamed();
}
}
class FieldDefDict : RefDict<FieldDef, FieldReference> {
Dictionary<ScopeAndTokenKey, FieldDef> tokenToFieldDef = new Dictionary<ScopeAndTokenKey, FieldDef>();
Dictionary<FieldReferenceKey, FieldDef> fieldRefToDef = new Dictionary<FieldReferenceKey, FieldDef>();
FieldDefinitionDict<FieldDef> fieldToDef = new FieldDefinitionDict<FieldDef>();
public int Count {
get { return tokenToFieldDef.Count; }
get { return fieldToDef.Count; }
}
public IEnumerable<FieldDef> getAll() {
return tokenToFieldDef.Values;
return fieldToDef.getAll();
}
public IEnumerable<FieldDef> 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<FieldDef>(fieldRefToDef.Values);
fieldRefToDef.Clear();
foreach (var fieldDef in all)
fieldRefToDef[new FieldReferenceKey(fieldDef.FieldDefinition)] = fieldDef;
fieldToDef.onTypesRenamed();
}
}
class MethodDefDict : RefDict<MethodDef, MethodReference> {
Dictionary<ScopeAndTokenKey, MethodDef> tokenToMethodDef = new Dictionary<ScopeAndTokenKey, MethodDef>();
Dictionary<MethodReferenceKey, MethodDef> methodRefToDef = new Dictionary<MethodReferenceKey, MethodDef>();
MethodDefinitionDict<MethodDef> methodToDef = new MethodDefinitionDict<MethodDef>();
public int Count {
get { return tokenToMethodDef.Count; }
get { return methodToDef.Count; }
}
public IEnumerable<MethodDef> getAll() {
return tokenToMethodDef.Values;
return methodToDef.getAll();
}
public IEnumerable<MethodDef> 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<MethodDef>(methodRefToDef.Values);
methodRefToDef.Clear();
foreach (var methodDef in all)
methodRefToDef[new MethodReferenceKey(methodDef.MethodDefinition)] = methodDef;
methodToDef.onTypesRenamed();
}
}
class PropertyDefDict : RefDict<PropertyDef, PropertyReference> {
Dictionary<ScopeAndTokenKey, PropertyDef> tokenToPropDef = new Dictionary<ScopeAndTokenKey, PropertyDef>();
Dictionary<PropertyReferenceKey, PropertyDef> propRefToDef = new Dictionary<PropertyReferenceKey, PropertyDef>();
PropertyDefinitionDict<PropertyDef> propToDef = new PropertyDefinitionDict<PropertyDef>();
public int Count {
get { return tokenToPropDef.Count; }
get { return propToDef.Count; }
}
public IEnumerable<PropertyDef> getAll() {
return tokenToPropDef.Values;
return propToDef.getAll();
}
public IEnumerable<PropertyDef> 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<PropertyDef>(propRefToDef.Values);
propRefToDef.Clear();
foreach (var propDef in all)
propRefToDef[new PropertyReferenceKey(propDef.PropertyDefinition)] = propDef;
propToDef.onTypesRenamed();
}
}
class EventDefDict : RefDict<EventDef, EventReference> {
Dictionary<ScopeAndTokenKey, EventDef> tokenToEventDef = new Dictionary<ScopeAndTokenKey, EventDef>();
Dictionary<EventReferenceKey, EventDef> eventRefToDef = new Dictionary<EventReferenceKey, EventDef>();
EventDefinitionDict<EventDef> eventToDef = new EventDefinitionDict<EventDef>();
public int Count {
get { return tokenToEventDef.Count; }
get { return eventToDef.Count; }
}
public IEnumerable<EventDef> getAll() {
return tokenToEventDef.Values;
return eventToDef.getAll();
}
public IEnumerable<EventDef> 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<EventDef>(eventRefToDef.Values);
eventRefToDef.Clear();
foreach (var eventDef in all)
eventRefToDef[new EventReferenceKey(eventDef.EventDefinition)] = eventDef;
eventToDef.onTypesRenamed();
}
}
}