private MethodReference ImportMethod(MethodReference method, ImportGenericContext context) { if (method.IsGenericInstance) { return(this.ImportMethodSpecification(method, context)); } TypeReference declaringType = this.ImportType(method.DeclaringType, context); MethodReference methodReference = new MethodReference { Name = method.Name, HasThis = method.HasThis, ExplicitThis = method.ExplicitThis, DeclaringType = declaringType, CallingConvention = method.CallingConvention }; if (method.HasGenericParameters) { MetadataImporter.ImportGenericParameters(methodReference, method); } context.Push(methodReference); MethodReference result; try { methodReference.ReturnType = this.ImportType(method.ReturnType, context); if (!method.HasParameters) { result = methodReference; } else { Collection <ParameterDefinition> parameters = method.Parameters; ParameterDefinitionCollection parameterDefinitionCollection = methodReference.parameters = new ParameterDefinitionCollection(methodReference, parameters.Count); for (int i = 0; i < parameters.Count; i++) { parameterDefinitionCollection.Add(new ParameterDefinition(this.ImportType(parameters[i].ParameterType, context))); } result = methodReference; } } finally { context.Pop(); } return(result); }
private TypeReference ImportType(TypeReference type, ImportGenericContext context) { if (type.IsTypeSpecification()) { return(this.ImportTypeSpecification(type, context)); } TypeReference typeReference = new TypeReference(type.Namespace, type.Name, this.module, this.ImportScope(type.Scope), type.IsValueType); MetadataSystem.TryProcessPrimitiveTypeReference(typeReference); if (type.IsNested) { typeReference.DeclaringType = this.ImportType(type.DeclaringType, context); } if (type.HasGenericParameters) { MetadataImporter.ImportGenericParameters(typeReference, type); } return(typeReference); }