3 // System.Reflection.Emit/MethodBuilder.cs
6 // Paolo Molaro (lupus@ximian.com)
8 // (C) 2001 Ximian, Inc. http://www.ximian.com
12 using System.Reflection;
13 using System.Reflection.Emit;
14 using System.Globalization;
15 using System.Runtime.CompilerServices;
17 namespace System.Reflection.Emit {
18 public sealed class MethodBuilder : MethodInfo {
19 private RuntimeMethodHandle mhandle;
21 private Type[] parameters;
22 private MethodAttributes attrs;
24 private int table_idx;
26 private ILGenerator ilgen;
27 internal TypeBuilder type;
28 private ParameterBuilder[] pinfo;
30 internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
32 this.attrs = attributes;
34 this.rtype = returnType;
35 if (parameterTypes != null) {
36 this.parameters = new Type [parameterTypes.Length];
37 System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
40 table_idx = tb.module.assemblyb.get_next_table_index (0x06, true);
43 public override Type ReturnType {get {return rtype;}}
44 public override Type ReflectedType {get {return null;}}
45 public override Type DeclaringType {get {return type;}}
46 public override string Name {get {return name;}}
47 public override RuntimeMethodHandle MethodHandle {get {return mhandle;}}
48 public override MethodAttributes Attributes {get {return attrs;}}
49 public override ICustomAttributeProvider ReturnTypeCustomAttributes {
52 public MethodToken GetToken() {
53 return new MethodToken(0x06000000 | table_idx);
56 public override MethodInfo GetBaseDefinition() {
59 public override MethodImplAttributes GetMethodImplementationFlags() {
60 return (MethodImplAttributes)0;
62 public override ParameterInfo[] GetParameters() {
67 * FIXME: this method signature needs to be expanded to handle also
70 public void CreateMethodBody( byte[] il, int count) {
71 code = new byte [count];
72 System.Array.Copy(il, code, count);
74 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
77 public override bool IsDefined (Type attribute_type, bool inherit) {
80 public override object[] GetCustomAttributes( bool inherit) {
83 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
86 public ILGenerator GetILGenerator () {
87 return GetILGenerator (256);
89 public ILGenerator GetILGenerator (int size) {
90 ilgen = new ILGenerator (this, size);
94 public ParameterBuilder DefineParameter( int position, ParameterAttributes attributes, string strParamName) {
95 ParameterBuilder pb = new ParameterBuilder (this, position, attributes, strParamName);
96 /* FIXME: add it to pinfo */
100 internal void fixup () {
102 ilgen.label_fixup ();