private MethodReference ImportMethod(MethodBase method, ImportGenericContext context, ReflectionImporter.ImportGenericKind import_kind) { if (ReflectionImporter.IsMethodSpecification(method) || ReflectionImporter.ImportOpenGenericMethod(method, import_kind)) { return(this.ImportMethodSpecification(method, context)); } TypeReference declaringType = this.ImportType(method.DeclaringType, context); if (ReflectionImporter.IsGenericInstance(method.DeclaringType)) { method = method.Module.ResolveMethod(method.MetadataToken); } MethodReference methodReference = new MethodReference { Name = method.Name, HasThis = ReflectionImporter.HasCallingConvention(method, CallingConventions.HasThis), ExplicitThis = ReflectionImporter.HasCallingConvention(method, CallingConventions.ExplicitThis), DeclaringType = this.ImportType(method.DeclaringType, context, ReflectionImporter.ImportGenericKind.Definition) }; if (ReflectionImporter.HasCallingConvention(method, CallingConventions.VarArgs)) { MethodReference expr_9C = methodReference; expr_9C.CallingConvention &= MethodCallingConvention.VarArg; } if (method.IsGenericMethod) { ReflectionImporter.ImportGenericParameters(methodReference, method.GetGenericArguments()); } context.Push(methodReference); MethodReference result; try { MethodInfo methodInfo = method as MethodInfo; methodReference.ReturnType = ((methodInfo != null) ? this.ImportType(methodInfo.ReturnType, context) : this.ImportType(typeof(void), default(ImportGenericContext))); ParameterInfo[] parameters = method.GetParameters(); Collection <ParameterDefinition> parameters2 = methodReference.Parameters; for (int i = 0; i < parameters.Length; i++) { parameters2.Add(new ParameterDefinition(this.ImportType(parameters[i].ParameterType, context))); } methodReference.DeclaringType = declaringType; result = methodReference; } finally { context.Pop(); } return(result); }
private TypeReference ImportType(Type type, ImportGenericContext context, ReflectionImporter.ImportGenericKind import_kind) { if (ReflectionImporter.IsTypeSpecification(type) || ReflectionImporter.ImportOpenGenericType(type, import_kind)) { return(this.ImportTypeSpecification(type, context)); } TypeReference typeReference = new TypeReference(string.Empty, type.Name, this.module, this.ImportScope(type.Assembly), type.IsValueType); typeReference.etype = ReflectionImporter.ImportElementType(type); if (ReflectionImporter.IsNestedType(type)) { typeReference.DeclaringType = this.ImportType(type.DeclaringType, context, import_kind); } else { typeReference.Namespace = (type.Namespace ?? string.Empty); } if (type.IsGenericType) { ReflectionImporter.ImportGenericParameters(typeReference, type.GetGenericArguments()); } return(typeReference); }