Merge pull request #948 from ermshiperete/bug-xamarin-2394
[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 #if !FULL_AOT_RUNTIME
35 using System;
36 using System.Globalization;
37 using System.Runtime.CompilerServices;
38 using System.Runtime.InteropServices;
39
40 namespace System.Reflection {
41         [StructLayout (LayoutKind.Sequential)]
42         internal class MonoArrayMethod: MethodInfo {
43 #pragma warning disable 649
44                 internal RuntimeMethodHandle mhandle;
45                 internal Type parent;
46                 internal Type ret;
47                 internal Type[] parameters;
48                 internal string name;
49                 internal int table_idx;
50                 internal CallingConventions call_conv;
51 #pragma warning restore 649             
52
53                 internal MonoArrayMethod (Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
54                         name = methodName;
55                         parent = arrayClass;
56                         ret = returnType;
57                         parameters = (Type[])parameterTypes.Clone();
58                         call_conv = callingConvention;
59                 }
60                 
61                 [MonoTODO("Always returns this")]
62                 public override MethodInfo GetBaseDefinition() {
63                         return this; /* FIXME */
64                 }
65                 public override Type ReturnType {
66                         get {
67                                 return ret;
68                         }
69                 }
70
71                 [MonoTODO("Not implemented.  Always returns null")]
72                 public override ICustomAttributeProvider ReturnTypeCustomAttributes { 
73                         get {return null;}
74                 }
75                 
76                 [MonoTODO("Not implemented.  Always returns zero")]
77                 public override MethodImplAttributes GetMethodImplementationFlags() {
78                         return (MethodImplAttributes)0;
79                 }
80
81                 [MonoTODO("Not implemented.  Always returns an empty array")]
82                 public override ParameterInfo[] GetParameters()
83                 {
84                         return GetParametersInternal ();                        
85                 }
86
87                 internal override ParameterInfo[] GetParametersInternal ()
88                 {
89                         return EmptyArray<ParameterInfo>.Value;
90                 }       
91                 
92                 [MonoTODO("Not implemented.  Always returns 0")]
93                 internal override int GetParametersCount ()
94                 {
95                         return 0;
96                 }               
97
98                 [MonoTODO("Not implemented")]
99                 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
100                         throw new NotImplementedException ();
101                 }
102
103                 public override RuntimeMethodHandle MethodHandle { 
104                         get {return mhandle;} 
105                 }
106
107                 [MonoTODO("Not implemented.  Always returns zero")]
108                 public override MethodAttributes Attributes { 
109                         get {
110                                 return (MethodAttributes)0;
111                         } 
112                 }
113                 
114                 public override Type ReflectedType {
115                         get {
116                                 return parent;
117                         }
118                 }
119                 public override Type DeclaringType {
120                         get {
121                                 return parent;
122                         }
123                 }
124                 public override string Name {
125                         get {
126                                 return name;
127                         }
128                 }
129                 
130                 public override bool IsDefined (Type attributeType, bool inherit) {
131                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
132                 }
133
134                 public override object[] GetCustomAttributes( bool inherit) {
135                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
136                 }
137                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
138                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
139                 }
140
141                 public override string ToString () {
142                         string parms = String.Empty;
143                         ParameterInfo[] p = GetParameters ();
144                         for (int i = 0; i < p.Length; ++i) {
145                                 if (i > 0)
146                                         parms = parms + ", ";
147                                 parms = parms + p [i].ParameterType.Name;
148                         }
149                         if (ReturnType != null)
150                                 return ReturnType.Name+" "+Name+"("+parms+")";
151                         else
152                                 return "void "+Name+"("+parms+")";
153                 }
154         }
155 }
156 #endif