5 // Jb Evain (jbevain@gmail.com)
7 // (C) 2005 - 2007 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.
29 namespace Mono
.Cecil
{
33 public class MethodReference
: MemberReference
, IMethodSignature
, IGenericParameterProvider
{
35 ParameterDefinitionCollection m_parameters
;
36 MethodReturnType m_returnType
;
40 MethodCallingConvention m_callConv
;
41 GenericParameterCollection m_genparams
;
43 public virtual bool HasThis
{
44 get { return m_hasThis; }
45 set { m_hasThis = value; }
48 public virtual bool ExplicitThis
{
49 get { return m_explicitThis; }
50 set { m_explicitThis = value; }
53 public virtual MethodCallingConvention CallingConvention
{
54 get { return m_callConv; }
55 set { m_callConv = value; }
58 public virtual bool HasParameters
{
59 get { return (m_parameters == null) ? false : (m_parameters.Count > 0); }
62 public virtual ParameterDefinitionCollection Parameters
{
64 if (m_parameters
== null)
65 m_parameters
= new ParameterDefinitionCollection (this);
70 public bool HasGenericParameters
{
71 get { return (m_genparams == null) ? false : (m_genparams.Count > 0); }
74 public GenericParameterCollection GenericParameters
{
76 if (m_genparams
== null)
77 m_genparams
= new GenericParameterCollection (this);
82 public virtual MethodReturnType ReturnType
{
83 get { return m_returnType;}
84 set { m_returnType = value; }
87 internal MethodReference (string name
, bool hasThis
,
88 bool explicitThis
, MethodCallingConvention callConv
) : this (name
)
90 m_parameters
= new ParameterDefinitionCollection (this);
92 m_explicitThis
= explicitThis
;
93 m_callConv
= callConv
;
96 internal MethodReference (string name
) : base (name
)
98 m_returnType
= new MethodReturnType (null);
101 public MethodReference (string name
,
102 TypeReference declaringType
, TypeReference returnType
,
103 bool hasThis
, bool explicitThis
, MethodCallingConvention callConv
) :
104 this (name
, hasThis
, explicitThis
, callConv
)
106 this.DeclaringType
= declaringType
;
107 this.ReturnType
.ReturnType
= returnType
;
110 public virtual MethodDefinition
Resolve ()
112 TypeReference declaringType
= DeclaringType
;
113 if (declaringType
== null)
116 return declaringType
.Module
.Resolver
.Resolve (this);
119 public virtual MethodReference
GetOriginalMethod ()
124 public int GetSentinel ()
127 for (int i
= 0; i
< Parameters
.Count
; i
++)
128 if (Parameters
[i
].ParameterType
is SentinelType
)
134 public override string ToString ()
136 int sentinel
= GetSentinel ();
138 StringBuilder sb
= new StringBuilder ();
139 sb
.Append (m_returnType
.ReturnType
.FullName
);
141 sb
.Append (base.ToString ());
143 if (this.HasParameters
) {
144 for (int i
= 0; i
< this.Parameters
.Count
; i
++) {
151 sb
.Append (this.Parameters
[i
].ParameterType
.FullName
);
155 return sb
.ToString ();