FeignClientMethodInfo BuildMethod(TypeBuilder typeBuilder, Type serviceType, MethodInfo method, FeignClientAttribute feignClientAttribute, RequestMappingBaseAttribute requestMapping) { FeignClientMethodInfo feignClientMethodInfo = new FeignClientMethodInfo { MethodId = GetMethodId(method), MethodMetadata = method }; //创建方法 MethodBuilder methodBuilder = CreateMethodBuilder(typeBuilder, method); ILGenerator iLGenerator = methodBuilder.GetILGenerator(); if (requestMapping == null) { //如果找不到mapping,抛出 NotSupportedException 异常 iLGenerator.Emit(OpCodes.Newobj, typeof(NotSupportedException).GetConstructor(Type.EmptyTypes)); iLGenerator.Emit(OpCodes.Throw); return(new FeignClientMethodInfo { MethodId = GetMethodId(method), MethodMetadata = method }); } string uri = requestMapping.Value ?? ""; LocalBuilder local_Uri = iLGenerator.DeclareLocal(typeof(string)); // 定义uri iLGenerator.Emit(OpCodes.Ldstr, uri); iLGenerator.Emit(OpCodes.Stloc, local_Uri); List <EmitRequestContent> emitRequestContents = EmitParameter(typeBuilder, requestMapping, iLGenerator, method, local_Uri); EmitCallMethod(typeBuilder, methodBuilder, iLGenerator, serviceType, feignClientMethodInfo, requestMapping, local_Uri, emitRequestContents); methodBuilder.CopyCustomAttributes(method); return(feignClientMethodInfo); }