2 Copyright (C) 2009 Jeroen Frijters
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.
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:
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.
27 namespace IKVM.Reflection
29 public abstract class MethodInfo : MethodBase, IGenericContext, IGenericBinder
31 // prevent external subclasses
36 public sealed override MemberTypes MemberType
38 get { return MemberTypes.Method; }
41 public abstract Type ReturnType { get; }
42 public abstract ParameterInfo ReturnParameter { get; }
44 public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments)
46 throw new NotSupportedException(this.GetType().FullName);
49 public virtual MethodInfo GetGenericMethodDefinition()
51 throw new NotSupportedException(this.GetType().FullName);
54 public override string ToString()
56 StringBuilder sb = new StringBuilder();
57 sb.Append(this.ReturnType.Name).Append(' ').Append(this.Name);
59 if (this.IsGenericMethod)
63 foreach (Type arg in GetGenericArguments())
65 sb.Append(sep).Append(arg);
72 foreach (ParameterInfo arg in GetParameters())
74 sb.Append(sep).Append(arg.ParameterType);
81 internal bool IsNewSlot
83 get { return (this.Attributes & MethodAttributes.NewSlot) != 0; }
86 public MethodInfo GetBaseDefinition()
88 MethodInfo match = this;
91 for (Type type = this.DeclaringType.BaseType; type != null && !match.IsNewSlot; type = type.BaseType)
93 MethodInfo method = type.FindMethod(this.Name, this.MethodSignature) as MethodInfo;
94 if (method != null && method.IsVirtual)
103 public virtual MethodInfo[] __GetMethodImpls()
105 throw new NotSupportedException();
108 Type IGenericContext.GetGenericTypeArgument(int index)
110 return this.DeclaringType.GetGenericTypeArgument(index);
113 Type IGenericContext.GetGenericMethodArgument(int index)
115 return GetGenericMethodArgument(index);
118 internal virtual Type GetGenericMethodArgument(int index)
120 throw new InvalidOperationException();
123 internal virtual int GetGenericMethodArgumentCount()
125 throw new InvalidOperationException();
128 internal override MethodInfo GetMethodOnTypeDefinition()
133 Type IGenericBinder.BindTypeParameter(Type type)
135 return this.DeclaringType.GetGenericTypeArgument(type.GenericParameterPosition);
138 Type IGenericBinder.BindMethodParameter(Type type)
140 return GetGenericMethodArgument(type.GenericParameterPosition);
143 internal override MethodBase BindTypeParameters(Type type)
145 return new GenericMethodInstance(this.DeclaringType.BindTypeParameters(type), this, null);
148 // This method is used by ILGenerator and exists to allow ArrayMethod to override it,
149 // because ArrayMethod doesn't have a working MethodAttributes property, so it needs
150 // to base the result of this on the CallingConvention.
151 internal virtual bool HasThis
153 get { return !IsStatic; }