3b73e1b24921d4ead0c5232ff5f6ed10a101819b
[mono.git] / mcs / class / referencesource / mscorlib / system / reflection / emit / methodbuilderinstantiation.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 // <OWNER>Microsoft</OWNER>
7 // 
8
9 namespace System.Reflection.Emit
10 {
11     using System;
12     using System.Reflection;
13     using System.Collections;
14     using System.Globalization;
15     using System.Diagnostics.Contracts;
16
17     internal sealed class MethodBuilderInstantiation : MethodInfo
18     {
19         #region Static Members
20         internal static MethodInfo MakeGenericMethod(MethodInfo method, Type[] inst)
21         {
22             if (!method.IsGenericMethodDefinition)
23                 throw new InvalidOperationException();
24             Contract.EndContractBlock();
25
26             return new MethodBuilderInstantiation(method, inst);
27         }
28
29         #endregion
30
31         #region Private Data Mebers
32         internal MethodInfo m_method;
33         private Type[] m_inst;
34         #endregion
35
36         #region Constructor
37         internal MethodBuilderInstantiation(MethodInfo method, Type[] inst)
38         {
39             m_method = method;
40             m_inst = inst;
41         }
42         #endregion
43         
44         internal override Type[] GetParameterTypes()
45         {
46             return m_method.GetParameterTypes();
47         }
48
49         #region MemberBase
50         public override MemberTypes MemberType { get { return m_method.MemberType;  } }
51         public override String Name { get { return m_method.Name; } }
52         public override Type DeclaringType { get { return m_method.DeclaringType;  } }
53         public override Type ReflectedType { get { return m_method.ReflectedType; } }
54         public override Object[] GetCustomAttributes(bool inherit) { return m_method.GetCustomAttributes(inherit); } 
55         public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { return m_method.GetCustomAttributes(attributeType, inherit); }
56         public override bool IsDefined(Type attributeType, bool inherit) { return m_method.IsDefined(attributeType, inherit); }
57         public override Module Module { get { return m_method.Module; } }
58         public new Type GetType() { return base.GetType(); }
59         #endregion
60
61         #region MethodBase Members
62         [Pure]
63         public override ParameterInfo[] GetParameters() { throw new NotSupportedException(); }        
64         public override MethodImplAttributes GetMethodImplementationFlags() { return m_method.GetMethodImplementationFlags(); }
65         public override RuntimeMethodHandle MethodHandle { get { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); } }
66         public override MethodAttributes Attributes { get { return m_method.Attributes; } }
67         public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
68         {
69             throw new NotSupportedException();
70         }
71         public override CallingConventions CallingConvention { get { return m_method.CallingConvention; } }
72         public override Type[] GetGenericArguments() { return m_inst; }
73         public override MethodInfo GetGenericMethodDefinition() { return m_method; }
74         public override bool IsGenericMethodDefinition { get { return false; } }
75         public override bool ContainsGenericParameters
76         {
77             get
78             {
79                 for (int i = 0; i < m_inst.Length; i++)
80                 {
81                     if (m_inst[i].ContainsGenericParameters)
82                         return true;
83                 }
84
85                 if (DeclaringType != null && DeclaringType.ContainsGenericParameters)
86                     return true;
87
88                 return false;
89             }
90         }
91
92         public override MethodInfo MakeGenericMethod(params Type[] arguments)
93         {
94            throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericMethodDefinition"));
95         }
96
97         public override bool IsGenericMethod { get { return true; } }
98        
99         #endregion
100
101         #region Public Abstract\Virtual Members
102         public override Type ReturnType
103         {
104             get
105             {
106                 return m_method.ReturnType;
107             }
108         }
109
110         public override ParameterInfo ReturnParameter { get { throw new NotSupportedException(); } }
111         public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { throw new NotSupportedException(); } }
112         public override MethodInfo GetBaseDefinition() { throw new NotSupportedException(); }
113         #endregion
114     }
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144