public void ResolveAllRefs(IResolver resolver) { foreach (var typeRef in memberRefFinder.TypeRefs.Keys) { var typeDef = resolver.ResolveType(typeRef); if (typeDef != null) { typeRefsToRename.Add(new RefToDef <TypeRef, TypeDef>(typeRef, typeDef.TypeDef)); } } foreach (var memberRef in memberRefFinder.MemberRefs.Keys) { if (memberRef.IsMethodRef) { var methodDef = resolver.ResolveMethod(memberRef); if (methodDef != null) { methodRefsToRename.Add(new RefToDef <MemberRef, MethodDef>(memberRef, methodDef.MethodDef)); } } else if (memberRef.IsFieldRef) { var fieldDef = resolver.ResolveField(memberRef); if (fieldDef != null) { fieldRefsToRename.Add(new RefToDef <MemberRef, FieldDef>(memberRef, fieldDef.FieldDef)); } } } foreach (var cattr in memberRefFinder.CustomAttributes.Keys) { var typeDef = resolver.ResolveType(cattr.AttributeType); if (typeDef == null) { continue; } if (cattr.NamedArguments == null) { continue; } for (int i = 0; i < cattr.NamedArguments.Count; i++) { var namedArg = cattr.NamedArguments[i]; if (namedArg.IsField) { var fieldDef = FindField(typeDef, namedArg.Name, namedArg.Type); if (fieldDef == null) { Logger.w("Could not find field {0} in attribute {1} ({2:X8})", Utils.ToCsharpString(namedArg.Name), Utils.ToCsharpString(typeDef.TypeDef.Name), typeDef.TypeDef.MDToken.ToInt32()); continue; } customAttributeFieldRefs.Add(new CustomAttributeRef(cattr, i, fieldDef.FieldDef)); } else { var propDef = FindProperty(typeDef, namedArg.Name, namedArg.Type); if (propDef == null) { Logger.w("Could not find property {0} in attribute {1} ({2:X8})", Utils.ToCsharpString(namedArg.Name), Utils.ToCsharpString(typeDef.TypeDef.Name), typeDef.TypeDef.MDToken.ToInt32()); continue; } customAttributePropertyRefs.Add(new CustomAttributeRef(cattr, i, propDef.PropertyDef)); } } } }
private static string ResolveField(IResolver objectResolver, ushort index) { IField field = objectResolver.ResolveField(index); if (null == field) { throw new REException(); } return field.FieldType.Name + "/" + field.Name; }