public MethodReference convert(MethodReference methodRef) { if (methodRef.GetType() != typeof(MethodReference) && methodRef.GetType() != typeof(MethodDefinition)) throw new ApplicationException("Invalid method reference type"); if (isInOurModule(methodRef)) return tryGetMethodDefinition(methodRef); return copy(methodRef); }
public MethodReference copy(MethodReference methodRef) { if (methodRef.GetType() != typeof(MethodReference) && methodRef.GetType() != typeof(MethodDefinition)) throw new ApplicationException("Invalid method reference type"); var newMethodRef = new MethodReference(methodRef.Name, convert(methodRef.MethodReturnType.ReturnType), convert(methodRef.DeclaringType)); newMethodRef.HasThis = methodRef.HasThis; newMethodRef.ExplicitThis = methodRef.ExplicitThis; newMethodRef.CallingConvention = methodRef.CallingConvention; foreach (var param in methodRef.Parameters) newMethodRef.Parameters.Add(new ParameterDefinition(param.Name, param.Attributes, convert(param.ParameterType))); foreach (var gp in methodRef.GenericParameters) newMethodRef.GenericParameters.Add(new GenericParameter(gp.Name, newMethodRef)); return newMethodRef; }
private void AssertMethodReferencesAreIdentical(MethodReference expected, MethodReference actual) { Assert.Equal(expected.GetType(), actual.GetType()); this.AssertGenericParametersAreIdentical(expected, actual); this.AssertTypeReferencesAreIdentical(expected.DeclaringType, actual.DeclaringType); if (expected is GenericInstanceMethod) { this.AssertGenericArgumentsAreIdentical((GenericInstanceMethod)expected, (GenericInstanceMethod)actual); } }