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.
29 using Mono.Collections.Generic;
31 namespace Mono.Cecil {
33 public sealed class EventDefinition : EventReference, IMemberDefinition {
37 Collection<CustomAttribute> custom_attributes;
39 internal MethodDefinition add_method;
40 internal MethodDefinition invoke_method;
41 internal MethodDefinition remove_method;
42 internal Collection<MethodDefinition> other_methods;
44 public EventAttributes Attributes {
45 get { return (EventAttributes) attributes; }
46 set { attributes = (ushort) value; }
49 public MethodDefinition AddMethod {
51 if (add_method != null)
57 set { add_method = value; }
60 public MethodDefinition InvokeMethod {
62 if (invoke_method != null)
68 set { invoke_method = value; }
71 public MethodDefinition RemoveMethod {
73 if (remove_method != null)
79 set { remove_method = value; }
82 public bool HasOtherMethods {
84 if (other_methods != null)
85 return other_methods.Count > 0;
88 return !other_methods.IsNullOrEmpty ();
92 public Collection<MethodDefinition> OtherMethods {
94 if (other_methods != null)
99 if (other_methods != null)
100 return other_methods;
102 return other_methods = new Collection<MethodDefinition> ();
106 public bool HasCustomAttributes {
108 if (custom_attributes != null)
109 return custom_attributes.Count > 0;
111 return this.GetHasCustomAttributes (Module);
115 public Collection<CustomAttribute> CustomAttributes {
116 get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); }
119 #region EventAttributes
121 public bool IsSpecialName {
122 get { return attributes.GetAttributes ((ushort) EventAttributes.SpecialName); }
123 set { attributes = attributes.SetAttributes ((ushort) EventAttributes.SpecialName, value); }
126 public bool IsRuntimeSpecialName {
127 get { return attributes.GetAttributes ((ushort) FieldAttributes.RTSpecialName); }
128 set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.RTSpecialName, value); }
133 public new TypeDefinition DeclaringType {
134 get { return (TypeDefinition) base.DeclaringType; }
135 set { base.DeclaringType = value; }
138 public override bool IsDefinition {
142 public EventDefinition (string name, EventAttributes attributes, TypeReference eventType)
143 : base (name, eventType)
145 this.attributes = (ushort) attributes;
146 this.token = new MetadataToken (TokenType.Event);
149 void InitializeMethods ()
151 if (add_method != null
152 || invoke_method != null
153 || remove_method != null)
156 var module = this.Module;
157 if (!module.HasImage ())
160 module.Read (this, (@event, reader) => reader.ReadMethods (@event));