26
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using Mono.Collections.Generic;
32
using RVA = System.UInt32;
29
34
namespace Mono.Cecil {
31
using Mono.Cecil.Binary;
34
public sealed class MethodDefinition : MethodReference, IMemberDefinition,
35
IHasSecurity, ICustomAttributeProvider {
37
public const string Cctor = ".cctor";
38
public const string Ctor = ".ctor";
40
MethodAttributes m_attributes;
41
MethodImplAttributes m_implAttrs;
42
MethodSemanticsAttributes m_semAttrs;
43
SecurityDeclarationCollection m_secDecls;
44
CustomAttributeCollection m_customAttrs;
48
OverrideCollection m_overrides;
49
PInvokeInfo m_pinvoke;
50
readonly ParameterDefinition m_this;
36
public sealed class MethodDefinition : MethodReference, IMemberDefinition, ISecurityDeclarationProvider {
39
ushort impl_attributes;
40
internal MethodSemanticsAttributes? sem_attrs;
41
Collection<CustomAttribute> custom_attributes;
42
Collection<SecurityDeclaration> security_declarations;
45
internal PInvokeInfo pinvoke;
46
Collection<MethodReference> overrides;
48
internal MethodBody body;
52
50
public MethodAttributes Attributes {
53
get { return m_attributes; }
54
set { m_attributes = value; }
51
get { return (MethodAttributes) attributes; }
52
set { attributes = (ushort) value; }
57
55
public MethodImplAttributes ImplAttributes {
58
get { return m_implAttrs; }
59
set { m_implAttrs = value; }
56
get { return (MethodImplAttributes) impl_attributes; }
57
set { impl_attributes = (ushort) value; }
62
60
public MethodSemanticsAttributes SemanticsAttributes {
63
get { return m_semAttrs; }
64
set { m_semAttrs = value; }
62
if (sem_attrs.HasValue)
63
return sem_attrs.Value;
67
return sem_attrs.Value;
70
sem_attrs = MethodSemanticsAttributes.None;
71
return sem_attrs.Value;
73
set { sem_attrs = value; }
76
internal void ReadSemantics ()
78
if (sem_attrs.HasValue)
81
var module = this.Module;
88
module.Read (this, (method, reader) => reader.ReadAllSemantics (method));
67
91
public bool HasSecurityDeclarations {
68
get { return (m_secDecls == null) ? false : (m_secDecls.Count > 0); }
71
public SecurityDeclarationCollection SecurityDeclarations {
73
if (m_secDecls == null)
74
m_secDecls = new SecurityDeclarationCollection (this);
93
if (security_declarations != null)
94
return security_declarations.Count > 0;
96
return this.GetHasSecurityDeclarations (Module);
100
public Collection<SecurityDeclaration> SecurityDeclarations {
101
get { return security_declarations ?? (security_declarations = this.GetSecurityDeclarations (Module)); }
80
104
public bool HasCustomAttributes {
81
get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
84
public CustomAttributeCollection CustomAttributes {
86
if (m_customAttrs == null)
87
m_customAttrs = new CustomAttributeCollection (this);
95
set { m_rva = value; }
106
if (custom_attributes != null)
107
return custom_attributes.Count > 0;
109
return this.GetHasCustomAttributes (Module);
113
public Collection<CustomAttribute> CustomAttributes {
114
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); }
118
get { return (int) rva; }
121
public bool HasBody {
123
return (attributes & (ushort) MethodAttributes.Abstract) == 0 &&
124
(attributes & (ushort) MethodAttributes.PInvokeImpl) == 0 &&
125
(impl_attributes & (ushort) MethodImplAttributes.InternalCall) == 0 &&
126
(impl_attributes & (ushort) MethodImplAttributes.Native) == 0 &&
127
(impl_attributes & (ushort) MethodImplAttributes.Unmanaged) == 0 &&
128
(impl_attributes & (ushort) MethodImplAttributes.Runtime) == 0;
98
132
public MethodBody Body {
103
set { m_body = value; }
140
if (HasImage && rva != 0)
141
return body = Module.Read (this, (method, reader) => reader.ReadMethodBody (method));
143
return body = new MethodBody (this);
145
set { body = value; }
148
public bool HasPInvokeInfo {
153
return IsPInvokeImpl;
106
157
public PInvokeInfo PInvokeInfo {
107
get { return m_pinvoke; }
108
set { m_pinvoke = value; }
162
if (HasImage && IsPInvokeImpl)
163
return pinvoke = Module.Read (this, (method, reader) => reader.ReadPInvokeInfo (method));
168
IsPInvokeImpl = true;
111
173
public bool HasOverrides {
112
get { return (m_overrides == null) ? false : (m_overrides.Count > 0); }
115
public OverrideCollection Overrides {
117
if (m_overrides == null)
118
m_overrides = new OverrideCollection (this);
124
public ParameterDefinition This {
125
get { return m_this; }
175
if (overrides != null)
176
return overrides.Count > 0;
179
return Module.Read (this, (method, reader) => reader.HasOverrides (method));
185
public Collection<MethodReference> Overrides {
187
if (overrides != null)
191
return overrides = Module.Read (this, (method, reader) => reader.ReadOverrides (method));
193
return overrides = new Collection<MethodReference> ();
197
public override bool HasGenericParameters {
199
if (generic_parameters != null)
200
return generic_parameters.Count > 0;
202
return this.GetHasGenericParameters (Module);
206
public override Collection<GenericParameter> GenericParameters {
207
get { return generic_parameters ?? (generic_parameters = this.GetGenericParameters (Module)); }
128
210
#region MethodAttributes
130
212
public bool IsCompilerControlled {
131
get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Compilercontrolled; }
134
m_attributes &= ~MethodAttributes.MemberAccessMask;
135
m_attributes |= MethodAttributes.Compilercontrolled;
137
m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Compilercontrolled);
213
get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.CompilerControlled); }
214
set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.CompilerControlled, value); }
141
217
public bool IsPrivate {
142
get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private; }
145
m_attributes &= ~MethodAttributes.MemberAccessMask;
146
m_attributes |= MethodAttributes.Private;
148
m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Private);
218
get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Private); }
219
set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Private, value); }
152
222
public bool IsFamilyAndAssembly {
153
get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem; }
156
m_attributes &= ~MethodAttributes.MemberAccessMask;
157
m_attributes |= MethodAttributes.FamANDAssem;
159
m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.FamANDAssem);
223
get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.FamANDAssem); }
224
set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.FamANDAssem, value); }
163
227
public bool IsAssembly {
164
get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assem; }
167
m_attributes &= ~MethodAttributes.MemberAccessMask;
168
m_attributes |= MethodAttributes.Assem;
170
m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Assem);
228
get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Assembly); }
229
set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Assembly, value); }
174
232
public bool IsFamily {
175
get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family; }
178
m_attributes &= ~MethodAttributes.MemberAccessMask;
179
m_attributes |= MethodAttributes.Family;
181
m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Family);
233
get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Family); }
234
set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Family, value); }
185
237
public bool IsFamilyOrAssembly {
186
get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem; }
189
m_attributes &= ~MethodAttributes.MemberAccessMask;
190
m_attributes |= MethodAttributes.FamORAssem;
192
m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.FamORAssem);
238
get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.FamORAssem); }
239
set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.FamORAssem, value); }
196
242
public bool IsPublic {
197
get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public; }
200
m_attributes &= ~MethodAttributes.MemberAccessMask;
201
m_attributes |= MethodAttributes.Public;
203
m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Public);
243
get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Public); }
244
set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.MemberAccessMask, (ushort) MethodAttributes.Public, value); }
207
247
public bool IsStatic {
208
get { return (m_attributes & MethodAttributes.Static) != 0; }
211
m_attributes |= MethodAttributes.Static;
213
m_attributes &= ~MethodAttributes.Static;
248
get { return attributes.GetAttributes ((ushort) MethodAttributes.Static); }
249
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.Static, value); }
217
252
public bool IsFinal {
218
get { return (m_attributes & MethodAttributes.Final) != 0; }
221
m_attributes |= MethodAttributes.Final;
223
m_attributes &= ~MethodAttributes.Final;
253
get { return attributes.GetAttributes ((ushort) MethodAttributes.Final); }
254
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.Final, value); }
227
257
public bool IsVirtual {
228
get { return (m_attributes & MethodAttributes.Virtual) != 0; }
231
m_attributes |= MethodAttributes.Virtual;
233
m_attributes &= ~MethodAttributes.Virtual;
258
get { return attributes.GetAttributes ((ushort) MethodAttributes.Virtual); }
259
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.Virtual, value); }
237
262
public bool IsHideBySig {
238
get { return (m_attributes & MethodAttributes.HideBySig) != 0; }
241
m_attributes |= MethodAttributes.HideBySig;
243
m_attributes &= ~MethodAttributes.HideBySig;
263
get { return attributes.GetAttributes ((ushort) MethodAttributes.HideBySig); }
264
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.HideBySig, value); }
247
267
public bool IsReuseSlot {
248
get { return (m_attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot; }
251
m_attributes &= ~MethodAttributes.VtableLayoutMask;
252
m_attributes |= MethodAttributes.ReuseSlot;
254
m_attributes &= ~(MethodAttributes.VtableLayoutMask & MethodAttributes.ReuseSlot);
268
get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.VtableLayoutMask, (ushort) MethodAttributes.ReuseSlot); }
269
set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.VtableLayoutMask, (ushort) MethodAttributes.ReuseSlot, value); }
258
272
public bool IsNewSlot {
259
get { return (m_attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot; }
262
m_attributes &= ~MethodAttributes.VtableLayoutMask;
263
m_attributes |= MethodAttributes.NewSlot;
265
m_attributes &= ~(MethodAttributes.VtableLayoutMask & MethodAttributes.NewSlot);
273
get { return attributes.GetMaskedAttributes ((ushort) MethodAttributes.VtableLayoutMask, (ushort) MethodAttributes.NewSlot); }
274
set { attributes = attributes.SetMaskedAttributes ((ushort) MethodAttributes.VtableLayoutMask, (ushort) MethodAttributes.NewSlot, value); }
269
public bool IsStrict {
270
get { return (m_attributes & MethodAttributes.Strict) != 0; }
273
m_attributes |= MethodAttributes.Strict;
275
m_attributes &= ~MethodAttributes.Strict;
277
public bool IsCheckAccessOnOverride {
278
get { return attributes.GetAttributes ((ushort) MethodAttributes.CheckAccessOnOverride); }
279
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.CheckAccessOnOverride, value); }
279
282
public bool IsAbstract {
280
get { return (m_attributes & MethodAttributes.Abstract) != 0; }
283
m_attributes |= MethodAttributes.Abstract;
285
m_attributes &= ~MethodAttributes.Abstract;
283
get { return attributes.GetAttributes ((ushort) MethodAttributes.Abstract); }
284
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.Abstract, value); }
289
287
public bool IsSpecialName {
290
get { return (m_attributes & MethodAttributes.SpecialName) != 0; }
293
m_attributes |= MethodAttributes.SpecialName;
295
m_attributes &= ~MethodAttributes.SpecialName;
288
get { return attributes.GetAttributes ((ushort) MethodAttributes.SpecialName); }
289
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.SpecialName, value); }
299
292
public bool IsPInvokeImpl {
300
get { return (m_attributes & MethodAttributes.PInvokeImpl) != 0; }
303
m_attributes |= MethodAttributes.PInvokeImpl;
305
m_attributes &= ~MethodAttributes.PInvokeImpl;
293
get { return attributes.GetAttributes ((ushort) MethodAttributes.PInvokeImpl); }
294
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.PInvokeImpl, value); }
309
297
public bool IsUnmanagedExport {
310
get { return (m_attributes & MethodAttributes.UnmanagedExport) != 0; }
313
m_attributes |= MethodAttributes.UnmanagedExport;
315
m_attributes &= ~MethodAttributes.UnmanagedExport;
298
get { return attributes.GetAttributes ((ushort) MethodAttributes.UnmanagedExport); }
299
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.UnmanagedExport, value); }
319
302
public bool IsRuntimeSpecialName {
320
get { return (m_attributes & MethodAttributes.RTSpecialName) != 0; }
323
m_attributes |= MethodAttributes.RTSpecialName;
325
m_attributes &= ~MethodAttributes.RTSpecialName;
303
get { return attributes.GetAttributes ((ushort) MethodAttributes.RTSpecialName); }
304
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.RTSpecialName, value); }
329
307
public bool HasSecurity {
330
get { return (m_attributes & MethodAttributes.HasSecurity) != 0; }
333
m_attributes |= MethodAttributes.HasSecurity;
335
m_attributes &= ~MethodAttributes.HasSecurity;
308
get { return attributes.GetAttributes ((ushort) MethodAttributes.HasSecurity); }
309
set { attributes = attributes.SetAttributes ((ushort) MethodAttributes.HasSecurity, value); }
341
314
#region MethodImplAttributes
343
316
public bool IsIL {
344
get { return (m_implAttrs & MethodImplAttributes.CodeTypeMask) == MethodImplAttributes.IL; }
347
m_implAttrs &= ~MethodImplAttributes.CodeTypeMask;
348
m_implAttrs |= MethodImplAttributes.IL;
350
m_implAttrs &= ~(MethodImplAttributes.CodeTypeMask & MethodImplAttributes.IL);
317
get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.IL); }
318
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.IL, value); }
354
321
public bool IsNative {
355
get { return (m_implAttrs & MethodImplAttributes.CodeTypeMask) == MethodImplAttributes.Native; }
358
m_implAttrs &= ~MethodImplAttributes.CodeTypeMask;
359
m_implAttrs |= MethodImplAttributes.Native;
361
m_implAttrs &= ~(MethodImplAttributes.CodeTypeMask & MethodImplAttributes.Native);
322
get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.Native); }
323
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.Native, value); }
365
326
public bool IsRuntime {
366
get { return (m_implAttrs & MethodImplAttributes.CodeTypeMask) == MethodImplAttributes.Runtime; }
369
m_implAttrs &= ~MethodImplAttributes.CodeTypeMask;
370
m_implAttrs |= MethodImplAttributes.Runtime;
372
m_implAttrs &= ~(MethodImplAttributes.CodeTypeMask & MethodImplAttributes.Runtime);
327
get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.Runtime); }
328
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.CodeTypeMask, (ushort) MethodImplAttributes.Runtime, value); }
376
331
public bool IsUnmanaged {
377
get { return (m_implAttrs & MethodImplAttributes.ManagedMask) == MethodImplAttributes.Unmanaged; }
380
m_implAttrs &= ~MethodImplAttributes.ManagedMask;
381
m_implAttrs |= MethodImplAttributes.Unmanaged;
383
m_implAttrs &= ~(MethodImplAttributes.ManagedMask & MethodImplAttributes.Unmanaged);
332
get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.ManagedMask, (ushort) MethodImplAttributes.Unmanaged); }
333
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.ManagedMask, (ushort) MethodImplAttributes.Unmanaged, value); }
387
336
public bool IsManaged {
388
get { return (m_implAttrs & MethodImplAttributes.ManagedMask) == MethodImplAttributes.Managed; }
391
m_implAttrs &= ~MethodImplAttributes.ManagedMask;
392
m_implAttrs |= MethodImplAttributes.Managed;
394
m_implAttrs &= ~(MethodImplAttributes.ManagedMask & MethodImplAttributes.Managed);
337
get { return impl_attributes.GetMaskedAttributes ((ushort) MethodImplAttributes.ManagedMask, (ushort) MethodImplAttributes.Managed); }
338
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort) MethodImplAttributes.ManagedMask, (ushort) MethodImplAttributes.Managed, value); }
398
341
public bool IsForwardRef {
399
get { return (m_implAttrs & MethodImplAttributes.ForwardRef) != 0; }
402
m_implAttrs |= MethodImplAttributes.ForwardRef;
404
m_implAttrs &= ~MethodImplAttributes.ForwardRef;
342
get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.ForwardRef); }
343
set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.ForwardRef, value); }
408
346
public bool IsPreserveSig {
409
get { return (m_implAttrs & MethodImplAttributes.PreserveSig) != 0; }
412
m_implAttrs |= MethodImplAttributes.PreserveSig;
414
m_implAttrs &= ~MethodImplAttributes.PreserveSig;
347
get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.PreserveSig); }
348
set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.PreserveSig, value); }
418
351
public bool IsInternalCall {
419
get { return (m_implAttrs & MethodImplAttributes.InternalCall) != 0; }
422
m_implAttrs |= MethodImplAttributes.InternalCall;
424
m_implAttrs &= ~MethodImplAttributes.InternalCall;
352
get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.InternalCall); }
353
set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.InternalCall, value); }
428
356
public bool IsSynchronized {
429
get { return (m_implAttrs & MethodImplAttributes.Synchronized) != 0; }
432
m_implAttrs |= MethodImplAttributes.Synchronized;
434
m_implAttrs &= ~MethodImplAttributes.Synchronized;
357
get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.Synchronized); }
358
set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.Synchronized, value); }
438
361
public bool NoInlining {
439
get { return (m_implAttrs & MethodImplAttributes.NoInlining) != 0; }
442
m_implAttrs |= MethodImplAttributes.NoInlining;
444
m_implAttrs &= ~MethodImplAttributes.NoInlining;
362
get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.NoInlining); }
363
set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.NoInlining, value); }
366
public bool NoOptimization {
367
get { return impl_attributes.GetAttributes ((ushort) MethodImplAttributes.NoOptimization); }
368
set { impl_attributes = impl_attributes.SetAttributes ((ushort) MethodImplAttributes.NoOptimization, value); }
450
373
#region MethodSemanticsAttributes
451
375
public bool IsSetter {
452
get { return (m_semAttrs & MethodSemanticsAttributes.Setter) != 0; }
455
m_semAttrs |= MethodSemanticsAttributes.Setter;
457
m_semAttrs &= ~MethodSemanticsAttributes.Setter;
376
get { return this.GetSemantics (MethodSemanticsAttributes.Setter); }
377
set { this.SetSemantics (MethodSemanticsAttributes.Setter, value); }
461
380
public bool IsGetter {
462
get { return (m_semAttrs & MethodSemanticsAttributes.Getter) != 0; }
465
m_semAttrs |= MethodSemanticsAttributes.Getter;
467
m_semAttrs &= ~MethodSemanticsAttributes.Getter;
381
get { return this.GetSemantics (MethodSemanticsAttributes.Getter); }
382
set { this.SetSemantics (MethodSemanticsAttributes.Getter, value); }
471
385
public bool IsOther {
472
get { return (m_semAttrs & MethodSemanticsAttributes.Other) != 0; }
475
m_semAttrs |= MethodSemanticsAttributes.Other;
477
m_semAttrs &= ~MethodSemanticsAttributes.Other;
386
get { return this.GetSemantics (MethodSemanticsAttributes.Other); }
387
set { this.SetSemantics (MethodSemanticsAttributes.Other, value); }
481
390
public bool IsAddOn {
482
get { return (m_semAttrs & MethodSemanticsAttributes.AddOn) != 0; }
485
m_semAttrs |= MethodSemanticsAttributes.AddOn;
487
m_semAttrs &= ~MethodSemanticsAttributes.AddOn;
391
get { return this.GetSemantics (MethodSemanticsAttributes.AddOn); }
392
set { this.SetSemantics (MethodSemanticsAttributes.AddOn, value); }
491
395
public bool IsRemoveOn {
492
get { return (m_semAttrs & MethodSemanticsAttributes.RemoveOn) != 0; }
495
m_semAttrs |= MethodSemanticsAttributes.RemoveOn;
497
m_semAttrs &= ~MethodSemanticsAttributes.RemoveOn;
396
get { return this.GetSemantics (MethodSemanticsAttributes.RemoveOn); }
397
set { this.SetSemantics (MethodSemanticsAttributes.RemoveOn, value); }
501
400
public bool IsFire {
502
get { return (m_semAttrs & MethodSemanticsAttributes.Fire) != 0; }
505
m_semAttrs |= MethodSemanticsAttributes.Fire;
507
m_semAttrs &= ~MethodSemanticsAttributes.Fire;
401
get { return this.GetSemantics (MethodSemanticsAttributes.Fire); }
402
set { this.SetSemantics (MethodSemanticsAttributes.Fire, value); }
513
public bool IsConstructor {
515
return this.IsRuntimeSpecialName && this.IsSpecialName &&
516
(this.Name == Cctor || this.Name == Ctor);
520
public bool HasBody {
522
return (m_attributes & MethodAttributes.Abstract) == 0 &&
523
(m_attributes & MethodAttributes.PInvokeImpl) == 0 &&
524
(m_implAttrs & MethodImplAttributes.InternalCall) == 0 &&
525
(m_implAttrs & MethodImplAttributes.Native) == 0 &&
526
(m_implAttrs & MethodImplAttributes.Unmanaged) == 0 &&
527
(m_implAttrs & MethodImplAttributes.Runtime) == 0;
531
407
public new TypeDefinition DeclaringType {
532
408
get { return (TypeDefinition) base.DeclaringType; }
533
409
set { base.DeclaringType = value; }
536
public MethodDefinition (string name, RVA rva,
537
MethodAttributes attrs, MethodImplAttributes implAttrs,
538
bool hasThis, bool explicitThis, MethodCallingConvention callConv) :
539
base (name, hasThis, explicitThis, callConv)
542
m_attributes = attrs;
543
m_implAttrs = implAttrs;
546
m_this = new ParameterDefinition ("this", 0, (ParameterAttributes) 0, null);
549
internal MethodDefinition (string name, MethodAttributes attrs) : base (name)
551
m_attributes = attrs;
412
public bool IsConstructor {
414
return this.IsRuntimeSpecialName
415
&& this.IsSpecialName
416
&& (this.Name == ".cctor" || this.Name == ".ctor");
420
public override bool IsDefinition {
424
internal MethodDefinition ()
426
this.token = new MetadataToken (TokenType.Method);
429
public MethodDefinition (string name, MethodAttributes attributes, TypeReference returnType)
430
: base (name, returnType)
432
this.attributes = (ushort) attributes;
553
433
this.HasThis = !this.IsStatic;
555
m_this = new ParameterDefinition ("this", 0, (ParameterAttributes) 0, null);
558
public MethodDefinition (string name, MethodAttributes attrs, TypeReference returnType) :
561
this.ReturnType.ReturnType = returnType;
564
internal void LoadBody ()
566
if (m_body == null && this.HasBody) {
567
m_body = new MethodBody (this);
569
ModuleDefinition module = DeclaringType != null ? DeclaringType.Module : null;
571
if (module != null && m_rva != RVA.Zero)
572
module.Controller.Reader.Code.VisitMethodBody (m_body);
434
this.token = new MetadataToken (TokenType.Method);
576
437
public override MethodDefinition Resolve ()
581
public MethodDefinition Clone ()
583
return Clone (this, new ImportContext (NullReferenceImporter.Instance, this));
586
internal static MethodDefinition Clone (MethodDefinition meth, ImportContext context)
588
MethodDefinition nm = new MethodDefinition (
595
meth.CallingConvention);
597
MethodReference contextMethod = context.GenericContext.Method;
599
context.GenericContext.Method = nm;
601
GenericParameter.CloneInto (meth, nm, context);
603
nm.ReturnType.ReturnType = context.Import (meth.ReturnType.ReturnType);
605
if (meth.ReturnType.Parameter != null) {
606
nm.ReturnType.Parameter = ParameterDefinition.Clone (meth.ReturnType.Parameter, context);
607
nm.ReturnType.Parameter.Method = nm;
610
if (meth.PInvokeInfo != null)
611
nm.PInvokeInfo = meth.PInvokeInfo; // TODO: import module ?
613
if (meth.HasParameters) {
614
foreach (ParameterDefinition param in meth.Parameters)
615
nm.Parameters.Add (ParameterDefinition.Clone (param, context));
617
if (meth.HasOverrides) {
618
foreach (MethodReference ov in meth.Overrides)
619
nm.Overrides.Add (context.Import (ov));
621
if (meth.HasCustomAttributes) {
622
foreach (CustomAttribute ca in meth.CustomAttributes)
623
nm.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
625
if (meth.HasSecurityDeclarations) {
626
foreach (SecurityDeclaration sec in meth.SecurityDeclarations)
627
nm.SecurityDeclarations.Add (SecurityDeclaration.Clone (sec));
630
if (meth.Body != null)
631
nm.Body = MethodBody.Clone (meth.Body, nm, context);
633
context.GenericContext.Method = contextMethod;
638
public override void Accept (IReflectionVisitor visitor)
640
visitor.VisitMethodDefinition (this);
642
this.GenericParameters.Accept (visitor);
643
this.Parameters.Accept (visitor);
645
if (this.PInvokeInfo != null)
646
this.PInvokeInfo.Accept (visitor);
648
this.SecurityDeclarations.Accept (visitor);
649
this.Overrides.Accept (visitor);
650
this.CustomAttributes.Accept (visitor);
443
static partial class Mixin {
445
public static ParameterDefinition GetParameter (this MethodBody self, int index)
447
var method = self.method;
449
if (method.HasThis) {
451
return self.ThisParameter;
456
var parameters = method.Parameters;
458
if (index < 0 || index >= parameters.size)
461
return parameters [index];
464
public static VariableDefinition GetVariable (this MethodBody self, int index)
466
var variables = self.Variables;
468
if (index < 0 || index >= variables.size)
471
return variables [index];
474
public static bool GetSemantics (this MethodDefinition self, MethodSemanticsAttributes semantics)
476
return (self.SemanticsAttributes & semantics) != 0;
479
public static void SetSemantics (this MethodDefinition self, MethodSemanticsAttributes semantics, bool value)
482
self.SemanticsAttributes |= semantics;
484
self.SemanticsAttributes &= ~semantics;