summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Reflection/Emit/SymbolMethod.cs
blob: 42713b86dbffdadb38553cbbb3cfbbe125efb383 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// 

namespace System.Reflection.Emit
{
    using System.Runtime.InteropServices;
    using System;
    using System.Reflection;
    using System.Diagnostics.Contracts;
    using CultureInfo = System.Globalization.CultureInfo;

    internal sealed class SymbolMethod : MethodInfo
    {
        #region Private Data Members
        private ModuleBuilder m_module;
        private Type m_containingType;
        private String m_name;
        private CallingConventions m_callingConvention;
        private Type m_returnType;
        private MethodToken m_mdMethod;
        private Type[] m_parameterTypes;
        private SignatureHelper m_signature;
        #endregion

        #region Constructor
        internal SymbolMethod(ModuleBuilder mod, MethodToken token, Type arrayClass, String methodName,
            CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
        {
            // This is a kind of MethodInfo to represent methods for array type of unbaked type

            // Another way to look at this class is as a glorified MethodToken wrapper. At the time of this comment
            // this class is only constructed inside ModuleBuilder.GetArrayMethod and the only interesting thing 
            // passed into it is this MethodToken. The MethodToken was forged using a TypeSpec for an Array type and
            // the name of the method on Array. 
            // As none of the methods on Array have CustomModifiers their is no need to pass those around in here.
            m_mdMethod = token;

            // The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders.
            m_returnType = returnType;
            if (parameterTypes != null)
            {
                m_parameterTypes = new Type[parameterTypes.Length];
                Array.Copy(parameterTypes, 0, m_parameterTypes, 0, parameterTypes.Length);
            }
            else
            {
                m_parameterTypes = Array.Empty<Type>();
            }

            m_module = mod;
            m_containingType = arrayClass;
            m_name = methodName;
            m_callingConvention = callingConvention;

            m_signature = SignatureHelper.GetMethodSigHelper(
                mod, callingConvention, returnType, null, null, parameterTypes, null, null);
        }
        #endregion

        #region Internal Members
        internal override Type[] GetParameterTypes()
        {
            return m_parameterTypes;
        }

        internal MethodToken GetToken(ModuleBuilder mod)
        {
            return mod.GetArrayMethodToken(m_containingType, m_name, m_callingConvention, m_returnType, m_parameterTypes);
        }

        #endregion

        #region MemberInfo Overrides
        public override Module Module
        {
            get { return m_module; }
        }

        public override Type ReflectedType
        {
            get { return m_containingType as Type; }
        }

        public override String Name
        {
            get { return m_name; }
        }

        public override Type DeclaringType
        {
            get { return m_containingType; }
        }
        #endregion

        #region MethodBase Overrides
        [Pure]
        public override ParameterInfo[] GetParameters()
        {
            throw new NotSupportedException(SR.NotSupported_SymbolMethod);
        }

        public override MethodImplAttributes GetMethodImplementationFlags()
        {
            throw new NotSupportedException(SR.NotSupported_SymbolMethod);
        }

        public override MethodAttributes Attributes
        {
            get { throw new NotSupportedException(SR.NotSupported_SymbolMethod); }
        }

        public override CallingConventions CallingConvention
        {
            get { return m_callingConvention; }
        }

        public override RuntimeMethodHandle MethodHandle
        {
            get { throw new NotSupportedException(SR.NotSupported_SymbolMethod); }
        }

        #endregion

        #region MethodInfo Overrides
        public override Type ReturnType
        {
            get
            {
                return m_returnType;
            }
        }

        public override ICustomAttributeProvider ReturnTypeCustomAttributes
        {
            get { return null; }
        }

        public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
        {
            throw new NotSupportedException(SR.NotSupported_SymbolMethod);
        }

        public override MethodInfo GetBaseDefinition()
        {
            return this;
        }
        #endregion

        #region ICustomAttributeProvider Implementation
        public override Object[] GetCustomAttributes(bool inherit)
        {
            throw new NotSupportedException(SR.NotSupported_SymbolMethod);
        }

        public override Object[] GetCustomAttributes(Type attributeType, bool inherit)
        {
            throw new NotSupportedException(SR.NotSupported_SymbolMethod);
        }

        public override bool IsDefined(Type attributeType, bool inherit)
        {
            throw new NotSupportedException(SR.NotSupported_SymbolMethod);
        }

        #endregion

        #region Public Members
        public Module GetModule()
        {
            return m_module;
        }

        public MethodToken GetToken()
        {
            return m_mdMethod;
        }

        #endregion
    }
}