Prevent race conditions for this cached variable, by using a temporary variable,...
[mono.git] / mcs / class / IKVM.Reflection / MethodBase.cs
1 /*
2   Copyright (C) 2009 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 using System;
25
26 namespace IKVM.Reflection
27 {
28         public abstract class MethodBase : MemberInfo
29         {
30                 // prevent external subclasses
31                 internal MethodBase()
32                 {
33                 }
34
35                 internal abstract MethodSignature MethodSignature { get; }
36                 internal abstract int ParameterCount { get; }
37                 public abstract ParameterInfo[] GetParameters();
38                 public abstract MethodAttributes Attributes { get; }
39                 public abstract MethodImplAttributes GetMethodImplementationFlags();
40                 public abstract MethodBody GetMethodBody();
41                 public abstract CallingConventions CallingConvention { get; }
42
43                 public bool IsConstructor
44                 {
45                         get
46                         {
47                                 if ((this.Attributes & MethodAttributes.RTSpecialName) != 0)
48                                 {
49                                         string name = this.Name;
50                                         return name == ConstructorInfo.ConstructorName || name == ConstructorInfo.TypeConstructorName;
51                                 }
52                                 return false;
53                         }
54                 }
55
56                 public bool IsStatic
57                 {
58                         get { return (Attributes & MethodAttributes.Static) != 0; }
59                 }
60
61                 public bool IsVirtual
62                 {
63                         get { return (Attributes & MethodAttributes.Virtual) != 0; }
64                 }
65
66                 public bool IsAbstract
67                 {
68                         get { return (Attributes & MethodAttributes.Abstract) != 0; }
69                 }
70
71                 public bool IsFinal
72                 {
73                         get { return (Attributes & MethodAttributes.Final) != 0; }
74                 }
75
76                 public bool IsPublic
77                 {
78                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public; }
79                 }
80
81                 public bool IsFamily
82                 {
83                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family; }
84                 }
85
86                 public bool IsFamilyOrAssembly
87                 {
88                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem; }
89                 }
90
91                 public bool IsAssembly
92                 {
93                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly; }
94                 }
95
96                 public bool IsFamilyAndAssembly
97                 {
98                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem; }
99                 }
100
101                 public bool IsPrivate
102                 {
103                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private; }
104                 }
105
106                 public bool IsSpecialName
107                 {
108                         get { return (Attributes & MethodAttributes.SpecialName) != 0; }
109                 }
110
111                 public bool IsHideBySig
112                 {
113                         get { return (Attributes & MethodAttributes.HideBySig) != 0; }
114                 }
115
116                 public virtual Type[] GetGenericArguments()
117                 {
118                         return Type.EmptyTypes;
119                 }
120
121                 public virtual bool IsGenericMethod
122                 {
123                         get { return false; }
124                 }
125
126                 public virtual bool IsGenericMethodDefinition
127                 {
128                         get { return false; }
129                 }
130
131                 public virtual bool ContainsGenericParameters
132                 {
133                         get { return IsGenericMethodDefinition; }
134                 }
135
136                 public virtual MethodBase __GetMethodOnTypeDefinition()
137                 {
138                         return this;
139                 }
140
141                 // This goes to the (uninstantiated) MethodInfo on the (uninstantiated) Type. For constructors
142                 // it also has the effect of removing the ConstructorInfo wrapper and returning the underlying MethodInfo.
143                 internal abstract MethodInfo GetMethodOnTypeDefinition();
144
145                 internal abstract int ImportTo(Emit.ModuleBuilder module);
146
147                 internal abstract MethodBase BindTypeParameters(Type type);
148         }
149 }