public void BuildMethod(ILConversion conversion, ConvertedTypeWithMethods_I input, MethodDefinition method) { if (input.IsGeneric() && input is ConvertedGenericTypeDefinition_I generic && generic.IsClosedType()) { return; } var methodEntry = new ConvertedBuiltMethod { MethodReference = method, DeclaringType = input, Conversion = conversion, MethodAttributes = BuildMethodAttributes(method), Name = method.Name }; if (!input.Methods.ByName.TryGetValue(methodEntry.Name, out List <SemanticMethodMask_I> methods)) { methods = new List <SemanticMethodMask_I>(); input.Methods.ByName.Add(methodEntry.Name, methods); } var callingConventions = Methods.GetCallingConventions(method); methods.Add(methodEntry); input.Routines.Add(methodEntry); methodEntry.MethodBuilder = input.TypeBuilder.DefineMethod(method.Name, methodEntry.MethodAttributes, callingConventions); // Needs method builder to create the generic parameters AddGenericParameters(conversion, input, methodEntry); var systemParameterTypes = Routines.Building.CreateParameters(conversion, methodEntry); var systemReturnType = Routines.Building.SetReturnType(conversion, methodEntry); methodEntry.MethodBuilder.SetSignature(systemReturnType, Type.EmptyTypes, Type.EmptyTypes, systemParameterTypes, null, null); // The 'CreateParameterBuilder' call has to called after the parameters are defined // in the define constructor call. Thus a second loop is needed. Routines.Building.CreateParameterBuilders(conversion, methodEntry); BuildBody(conversion, method, methodEntry); SetImplementationFlagsIfPresent(method, methodEntry.MethodBuilder); CustomAttributes.BuildCustomAttributes(conversion, input, methodEntry); if (method.MethodReturnType.HasCustomAttributes) { var returnParameter = methodEntry.MethodBuilder.DefineParameter(0, System.Reflection.ParameterAttributes.Retval, null); CustomAttributes.BuildCustomAttributes(conversion, returnParameter, method.MethodReturnType); } }
public void BuildCustomAttributes(ILConversion conversion, ConvertedTypeWithMethods_I input, ConvertedBuiltMethod methodEntry) { var methodDefinition = (MethodDefinition)methodEntry.MethodReference; var builders = CreateCustomAttributeList(conversion, methodDefinition.CustomAttributes); for (int i = 0; i < builders.Count; i++) { var builder1 = builders[i]; methodEntry.MethodBuilder.SetCustomAttribute(builder1); } //builders = CreateCustomAttributeList(conversion, methodDefinition.MethodReturnType.CustomAttributes); //for (int i = 0; i < builders.Count; i++) //{ // var builder1 = builders[i]; //} }