3 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // System.Reflection.Emit/EventBuilder.cs
29 // Paolo Molaro (lupus@ximian.com)
31 // (C) 2001 Ximian, Inc. http://www.ximian.com
35 using System.Reflection;
36 using System.Reflection.Emit;
37 using System.Globalization;
38 using System.Runtime.CompilerServices;
39 using System.Runtime.InteropServices;
41 namespace System.Reflection.Emit {
43 [ComDefaultInterface (typeof (_EventBuilder))]
44 [ClassInterface (ClassInterfaceType.None)]
45 [StructLayout (LayoutKind.Sequential)]
46 public sealed class EventBuilder : _EventBuilder {
47 #pragma warning disable 169, 414
51 CustomAttributeBuilder[] cattrs;
52 internal MethodBuilder add_method;
53 internal MethodBuilder remove_method;
54 internal MethodBuilder raise_method;
55 internal MethodBuilder[] other_methods;
56 internal EventAttributes attrs;
58 #pragma warning restore 169, 414
60 internal EventBuilder (TypeBuilder tb, string eventName, EventAttributes eventAttrs, Type eventType) {
65 table_idx = get_next_table_index (this, 0x14, true);
68 internal int get_next_table_index (object obj, int table, bool inc) {
69 return typeb.get_next_table_index (obj, table, inc);
72 public void AddOtherMethod( MethodBuilder mdBuilder) {
73 if (mdBuilder == null)
74 throw new ArgumentNullException ("mdBuilder");
76 if (other_methods != null) {
77 MethodBuilder[] newv = new MethodBuilder [other_methods.Length + 1];
78 other_methods.CopyTo (newv, 0);
81 other_methods = new MethodBuilder [1];
83 other_methods [other_methods.Length - 1] = mdBuilder;
86 public EventToken GetEventToken () {
87 return new EventToken (0x14000000 | table_idx);
89 public void SetAddOnMethod( MethodBuilder mdBuilder) {
90 if (mdBuilder == null)
91 throw new ArgumentNullException ("mdBuilder");
93 add_method = mdBuilder;
95 public void SetRaiseMethod( MethodBuilder mdBuilder) {
96 if (mdBuilder == null)
97 throw new ArgumentNullException ("mdBuilder");
99 raise_method = mdBuilder;
101 public void SetRemoveOnMethod( MethodBuilder mdBuilder) {
102 if (mdBuilder == null)
103 throw new ArgumentNullException ("mdBuilder");
105 remove_method = mdBuilder;
108 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
109 if (customBuilder == null)
110 throw new ArgumentNullException ("customBuilder");
112 string attrname = customBuilder.Ctor.ReflectedType.FullName;
113 if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
114 attrs |= EventAttributes.SpecialName;
117 if (cattrs != null) {
118 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
119 cattrs.CopyTo (new_array, 0);
120 new_array [cattrs.Length] = customBuilder;
123 cattrs = new CustomAttributeBuilder [1];
124 cattrs [0] = customBuilder;
129 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
131 throw new ArgumentNullException ("con");
132 if (binaryAttribute == null)
133 throw new ArgumentNullException ("binaryAttribute");
134 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
137 private void RejectIfCreated () {
138 if (typeb.is_created)
139 throw new InvalidOperationException ("Type definition of the method is complete.");
142 void _EventBuilder.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
144 throw new NotImplementedException ();
147 void _EventBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
149 throw new NotImplementedException ();
152 void _EventBuilder.GetTypeInfoCount (out uint pcTInfo)
154 throw new NotImplementedException ();
157 void _EventBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
159 throw new NotImplementedException ();