public static void CheckReferences(ModuleDefinition m) { foreach (var t in m.Types) { TypeVisitor.VisitAllMemberRefs(t, x => { var resolved = x.Resolve(); var mod = resolved.DeclaringType.Module; if (mod.Name != "CommonLanguageRuntimeLibrary" && resolved.DeclaringType.Name != "C" && mod != m) { Debug.Assert(false); } return(x); }); TypeVisitor.VisitAllTypeRefsMemberTypeRefs(t, x => { if (x.IsPointer) { x = x.GetElementType(); } var resolved = x.Resolve(); if (resolved.Module.Name != "CommonLanguageRuntimeLibrary" && resolved.Module != m) { Debug.Assert(false); } }); } }
public static void ImportReferences(ModuleDefinition m) { foreach (var t in m.Types) { TypeVisitor.VisitAllMemberRefs(t, x => { if (x is MethodReference) { return(m.ImportReference((MethodReference)x)); } if (x is FieldReference) { return(m.ImportReference((FieldReference)x)); } return(x); }); TypeVisitor.ReplaceTypeRefs(t, x => m.ImportReference(x)); foreach (var c in t.CustomAttributes) { c.Constructor = m.ImportReference(c.Constructor); } foreach (var me in t.Methods) { foreach (var c in me.CustomAttributes) { c.Constructor = m.ImportReference(c.Constructor); } } } }