private static void Fix(FieldReference field) { if (!MatchesPlatform(field.FieldType)) { field.FieldType = ReferenceResolver.Fix(field.Module, field.FieldType); } }
private static void Fix(TypeDefinition type) { if (type.BaseType != null) { type.BaseType = ReferenceResolver.Fix(type.Module, type.BaseType); } for (var i = 0; i < type.Interfaces.Count; ++i) { type.Interfaces[i] = ReferenceResolver.Fix(type.Module, type.Interfaces[i]); } foreach (var obj in type.Events) { if (obj.AddMethod != null) { Fix(obj.AddMethod); } if (obj.InvokeMethod != null) { Fix(obj.InvokeMethod); } if (obj.RemoveMethod != null) { Fix(obj.RemoveMethod); } foreach (var method in obj.OtherMethods) { Fix(method); } obj.EventType = ReferenceResolver.Fix(type.Module, obj.EventType); } for (var i = 0; i < type.GenericParameters.Count; ++i) { type.GenericParameters[i] = ReferenceResolver.Fix(type.Module, type, type.GenericParameters[i]); } foreach (var obj in type.NestedTypes) { Fix(obj); } foreach (var obj in type.Methods) { Fix(obj); } foreach (var obj in type.Fields) { Fix(obj); } }
internal static void Fix(AssemblyDefinition def) { foreach (var mod in def.Modules) { foreach (var obj in mod.GetTypes()) { Fix(obj); } var refs = (TypeReference[])mod.GetTypeReferences(); for (var i = 0; i < refs.Length; ++i) { if (!MatchesPlatform(refs[i])) { refs[i] = ReferenceResolver.Fix(mod, refs[i]); } } } }
private static void Fix(MethodDefinition meth) { foreach (var obj in meth.Parameters) { if (!MatchesPlatform(obj.ParameterType)) { obj.ParameterType = ReferenceResolver.Fix(meth.Module, obj.ParameterType); } } if (!MatchesPlatform(meth.MethodReturnType.ReturnType)) { meth.MethodReturnType.ReturnType = ReferenceResolver.Fix(meth.Module, meth.MethodReturnType.ReturnType); } for (int i = 0; i < meth.Overrides.Count; ++i) { meth.Overrides[i] = ReferenceResolver.Fix(meth.Module, meth.Overrides[i]); } if (!meth.HasBody || meth.Body == null) { return; } if (meth.Body.ThisParameter != null && !MatchesPlatform(meth.Body.ThisParameter.ParameterType)) { meth.Body.ThisParameter.ParameterType = ReferenceResolver.Fix(meth.Module, meth.Body.ThisParameter.ParameterType); } if (meth.Body.HasVariables) { foreach (var v in meth.Body.Variables) { v.VariableType = ReferenceResolver.Fix(meth.Module, v.VariableType); } } foreach (var insn in meth.Body.Instructions) { var oper = insn.Operand; var asType = oper as TypeReference; var asMeth = oper as MethodReference; var asField = oper as FieldReference; var asVar = oper as VariableDefinition; var asParam = oper as ParameterDefinition; var asCall = oper as CallSite; if (asType != null) { insn.Operand = ReferenceResolver.Fix(meth.Module, asType); } else if (asMeth != null) { insn.Operand = ReferenceResolver.Fix(meth.Module, asMeth); } else if (asField != null) { insn.Operand = ReferenceResolver.Fix(meth.Module, asField); } else if (asVar != null) { asVar.VariableType = ReferenceResolver.Fix(meth.Module, asVar.VariableType); } else if (asParam != null) { asParam.ParameterType = ReferenceResolver.Fix(meth.Module, asParam.ParameterType); } else if (asCall != null) { foreach (var param in asCall.Parameters) { param.ParameterType = ReferenceResolver.Fix(meth.Module, param.ParameterType); } asCall.ReturnType = ReferenceResolver.Fix(meth.Module, asCall.ReturnType); } } }