5
// Jb Evain (jbevain@gmail.com)
7
// Copyright (c) 2008 - 2010 Jb Evain
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
using Mono.Collections.Generic;
34
namespace Mono.Cecil {
36
public class MethodReference : MemberReference, IMethodSignature, IGenericParameterProvider, IGenericContext {
38
internal ParameterDefinitionCollection parameters;
39
MethodReturnType return_type;
43
MethodCallingConvention calling_convention;
44
internal Collection<GenericParameter> generic_parameters;
46
public virtual bool HasThis {
47
get { return has_this; }
48
set { has_this = value; }
51
public virtual bool ExplicitThis {
52
get { return explicit_this; }
53
set { explicit_this = value; }
56
public virtual MethodCallingConvention CallingConvention {
57
get { return calling_convention; }
58
set { calling_convention = value; }
61
public virtual bool HasParameters {
62
get { return !parameters.IsNullOrEmpty (); }
65
public virtual Collection<ParameterDefinition> Parameters {
67
if (parameters == null)
68
parameters = new ParameterDefinitionCollection (this);
74
IGenericParameterProvider IGenericContext.Type {
76
var declaring_type = this.DeclaringType;
77
var instance = declaring_type as GenericInstanceType;
79
return instance.ElementType;
81
return declaring_type;
85
IGenericParameterProvider IGenericContext.Method {
89
GenericParameterType IGenericParameterProvider.GenericParameterType {
90
get { return GenericParameterType.Method; }
93
public virtual bool HasGenericParameters {
94
get { return !generic_parameters.IsNullOrEmpty (); }
97
public virtual Collection<GenericParameter> GenericParameters {
99
if (generic_parameters != null)
100
return generic_parameters;
102
return generic_parameters = new Collection<GenericParameter> ();
106
public TypeReference ReturnType {
108
var return_type = MethodReturnType;
109
return return_type != null ? return_type.ReturnType : null;
112
var return_type = MethodReturnType;
113
if (return_type != null)
114
return_type.ReturnType = value;
118
public virtual MethodReturnType MethodReturnType {
119
get { return return_type; }
120
set { return_type = value; }
123
public override string FullName {
125
var builder = new StringBuilder ();
126
builder.Append (ReturnType.FullName);
127
builder.Append (" ");
128
builder.Append (MemberFullName ());
129
this.MethodSignatureFullName (builder);
130
return builder.ToString ();
134
public virtual bool IsGenericInstance {
135
get { return false; }
138
internal override bool ContainsGenericParameter {
140
if (this.ReturnType.ContainsGenericParameter || base.ContainsGenericParameter)
143
var parameters = this.Parameters;
145
for (int i = 0; i < parameters.Count; i++)
146
if (parameters [i].ParameterType.ContainsGenericParameter)
153
internal MethodReference ()
155
this.return_type = new MethodReturnType (this);
156
this.token = new MetadataToken (TokenType.MemberRef);
159
public MethodReference (string name, TypeReference returnType)
162
if (returnType == null)
163
throw new ArgumentNullException ("returnType");
165
this.return_type = new MethodReturnType (this);
166
this.return_type.ReturnType = returnType;
167
this.token = new MetadataToken (TokenType.MemberRef);
170
public MethodReference (string name, TypeReference returnType, TypeReference declaringType)
171
: this (name, returnType)
173
if (declaringType == null)
174
throw new ArgumentNullException ("declaringType");
176
this.DeclaringType = declaringType;
179
public virtual MethodReference GetElementMethod ()
184
public virtual MethodDefinition Resolve ()
186
var module = this.Module;
188
throw new NotSupportedException ();
190
return module.Resolve (this);
194
static partial class Mixin {
196
public static bool IsVarArg (this IMethodSignature self)
198
return (self.CallingConvention & MethodCallingConvention.VarArg) != 0;
201
public static int GetSentinelPosition (this IMethodSignature self)
203
if (!self.HasParameters)
206
var parameters = self.Parameters;
207
for (int i = 0; i < parameters.Count; i++)
208
if (parameters [i].ParameterType.IsSentinel)