Merge pull request #231 from linquize/a853199c497bb0977970974303fac7e42080809d
[mono.git] / mcs / class / corlib / System.Reflection.Emit / MonoArrayMethod.cs
1 //
2 // System.Reflection/MonoMethod.cs
3 // The class used to represent methods from the mono runtime.
4 //
5 // Author:
6 //   Paolo Molaro (lupus@ximian.com)
7 //
8 // (C) 2001 Ximian, Inc.  http://www.ximian.com
9 //
10
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System;
35 using System.Globalization;
36 using System.Runtime.CompilerServices;
37 using System.Runtime.InteropServices;
38
39 namespace System.Reflection {
40         [StructLayout (LayoutKind.Sequential)]
41         internal class MonoArrayMethod: MethodInfo {
42 #pragma warning disable 649
43                 internal RuntimeMethodHandle mhandle;
44                 internal Type parent;
45                 internal Type ret;
46                 internal Type[] parameters;
47                 internal string name;
48                 internal int table_idx;
49                 internal CallingConventions call_conv;
50 #pragma warning restore 649             
51
52                 internal MonoArrayMethod (Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
53                         name = methodName;
54                         parent = arrayClass;
55                         ret = returnType;
56                         parameters = (Type[])parameterTypes.Clone();
57                         call_conv = callingConvention;
58                 }
59                 
60                 [MonoTODO("Always returns this")]
61                 public override MethodInfo GetBaseDefinition() {
62                         return this; /* FIXME */
63                 }
64                 public override Type ReturnType {
65                         get {
66                                 return ret;
67                         }
68                 }
69
70                 [MonoTODO("Not implemented.  Always returns null")]
71                 public override ICustomAttributeProvider ReturnTypeCustomAttributes { 
72                         get {return null;}
73                 }
74                 
75                 [MonoTODO("Not implemented.  Always returns zero")]
76                 public override MethodImplAttributes GetMethodImplementationFlags() {
77                         return (MethodImplAttributes)0;
78                 }
79
80                 [MonoTODO("Not implemented.  Always returns an empty array")]
81                 public override ParameterInfo[] GetParameters() {
82                         return new ParameterInfo [0];
83                 }
84                 
85                 [MonoTODO("Not implemented.  Always returns 0")]
86                 internal override int GetParameterCount ()
87                 {
88                         return 0;
89                 }               
90
91                 [MonoTODO("Not implemented")]
92                 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
93                         throw new NotImplementedException ();
94                 }
95
96                 public override RuntimeMethodHandle MethodHandle { 
97                         get {return mhandle;} 
98                 }
99
100                 [MonoTODO("Not implemented.  Always returns zero")]
101                 public override MethodAttributes Attributes { 
102                         get {
103                                 return (MethodAttributes)0;
104                         } 
105                 }
106                 
107                 public override Type ReflectedType {
108                         get {
109                                 return parent;
110                         }
111                 }
112                 public override Type DeclaringType {
113                         get {
114                                 return parent;
115                         }
116                 }
117                 public override string Name {
118                         get {
119                                 return name;
120                         }
121                 }
122                 
123                 public override bool IsDefined (Type attributeType, bool inherit) {
124                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
125                 }
126
127                 public override object[] GetCustomAttributes( bool inherit) {
128                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
129                 }
130                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
131                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
132                 }
133
134                 public override string ToString () {
135                         string parms = String.Empty;
136                         ParameterInfo[] p = GetParameters ();
137                         for (int i = 0; i < p.Length; ++i) {
138                                 if (i > 0)
139                                         parms = parms + ", ";
140                                 parms = parms + p [i].ParameterType.Name;
141                         }
142                         if (ReturnType != null)
143                                 return ReturnType.Name+" "+Name+"("+parms+")";
144                         else
145                                 return "void "+Name+"("+parms+")";
146                 }
147         }
148 }