1: public IGenerationContext CreateMethod(TypeBuilder typeBuilder, MethodInfo method)
2: { 3: Type[] parameterTypes = GetParameterTypes(method);
4: MethodAttributes attributes = MethodAttributes.Public;
5: if (!method.IsFinal)
6: attributes |= MethodAttributes.Virtual;
7:
8: MethodBuilder methodInfoBody = typeBuilder.DefineMethod(
9: method.Name,
10: attributes,
11: method.CallingConvention,
12: method.ReturnType,
13: parameterTypes);
14:
15: methodInfoBody.InitLocals = true;
16:
17: if (method.IsGenericMethodDefinition)
18: { 19: Type[] genericParameterTypes = method.GetGenericArguments();
20: string[] names = new string[genericParameterTypes.Length];
21: for (int i = 0; i < genericParameterTypes.Length; i++)
22: names[i] = "T" + i.ToString();
23: GenericTypeParameterBuilder[] genericParams = methodInfoBody.DefineGenericParameters(names);
24: }
25: ILGenerator generator = methodInfoBody.GetILGenerator();
26: return GenerationContext.SetCurrentContext(typeBuilder,generator, method);
27: }