do not check order sequence if option /order was not used
[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                 public abstract int __MethodRVA { get; }
43
44                 public bool IsConstructor
45                 {
46                         get
47                         {
48                                 if ((this.Attributes & MethodAttributes.RTSpecialName) != 0)
49                                 {
50                                         string name = this.Name;
51                                         return name == ConstructorInfo.ConstructorName || name == ConstructorInfo.TypeConstructorName;
52                                 }
53                                 return false;
54                         }
55                 }
56
57                 public bool IsStatic
58                 {
59                         get { return (Attributes & MethodAttributes.Static) != 0; }
60                 }
61
62                 public bool IsVirtual
63                 {
64                         get { return (Attributes & MethodAttributes.Virtual) != 0; }
65                 }
66
67                 public bool IsAbstract
68                 {
69                         get { return (Attributes & MethodAttributes.Abstract) != 0; }
70                 }
71
72                 public bool IsFinal
73                 {
74                         get { return (Attributes & MethodAttributes.Final) != 0; }
75                 }
76
77                 public bool IsPublic
78                 {
79                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public; }
80                 }
81
82                 public bool IsFamily
83                 {
84                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family; }
85                 }
86
87                 public bool IsFamilyOrAssembly
88                 {
89                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem; }
90                 }
91
92                 public bool IsAssembly
93                 {
94                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly; }
95                 }
96
97                 public bool IsFamilyAndAssembly
98                 {
99                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem; }
100                 }
101
102                 public bool IsPrivate
103                 {
104                         get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private; }
105                 }
106
107                 public bool IsSpecialName
108                 {
109                         get { return (Attributes & MethodAttributes.SpecialName) != 0; }
110                 }
111
112                 public bool IsHideBySig
113                 {
114                         get { return (Attributes & MethodAttributes.HideBySig) != 0; }
115                 }
116
117                 public virtual Type[] GetGenericArguments()
118                 {
119                         return Type.EmptyTypes;
120                 }
121
122                 public virtual bool IsGenericMethod
123                 {
124                         get { return false; }
125                 }
126
127                 public virtual bool IsGenericMethodDefinition
128                 {
129                         get { return false; }
130                 }
131
132                 public virtual bool ContainsGenericParameters
133                 {
134                         get { return IsGenericMethodDefinition; }
135                 }
136
137                 public virtual MethodBase __GetMethodOnTypeDefinition()
138                 {
139                         return this;
140                 }
141
142                 // This goes to the (uninstantiated) MethodInfo on the (uninstantiated) Type. For constructors
143                 // it also has the effect of removing the ConstructorInfo wrapper and returning the underlying MethodInfo.
144                 internal abstract MethodInfo GetMethodOnTypeDefinition();
145
146                 internal abstract int ImportTo(Emit.ModuleBuilder module);
147
148                 internal abstract MethodBase BindTypeParameters(Type type);
149
150                 internal sealed override bool BindingFlagsMatch(BindingFlags flags)
151                 {
152                         return BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
153                                 && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static, BindingFlags.Instance);
154                 }
155
156                 internal sealed override bool BindingFlagsMatchInherited(BindingFlags flags)
157                 {
158                         return (Attributes & MethodAttributes.MemberAccessMask) > MethodAttributes.Private
159                                 && BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
160                                 && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static | BindingFlags.FlattenHierarchy, BindingFlags.Instance);
161                 }
162         }
163 }