Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy / Builder / CodeBuilder / EasyEvent.cs
blob5ec1c25f02f939f9dda92ed65f23b438fe15d2b2
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.DynamicProxy.Builder.CodeBuilder
17 using System;
18 using System.Reflection;
19 using System.Reflection.Emit;
21 using Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST;
22 using Castle.DynamicProxy.Builder.CodeBuilder.Utils;
24 /// <summary>
25 /// Summary description for EasyEvent.
26 /// </summary>
27 [CLSCompliant(false)]
28 public class EasyEvent : IEasyMember
30 private EventBuilder m_builder;
31 private AbstractEasyType m_maintype;
32 private EasyMethod m_addOnMethod;
33 private EasyMethod m_removeOnMethod;
34 private string m_name;
36 public EasyEvent(AbstractEasyType maintype, String name, Type eventHandlerType)
38 m_name = name;
39 m_maintype = maintype;
40 m_builder = maintype.TypeBuilder.DefineEvent(
41 name, EventAttributes.None, eventHandlerType);
44 public String Name
46 get { return m_name; }
49 public EasyMethod CreateAddOnMethod(MethodAttributes atts, params Type[] parameters)
51 if (m_addOnMethod == null)
53 m_addOnMethod =
54 new EasyMethod(m_maintype, "add_" + Name, atts, new ReturnReferenceExpression(typeof(void)), ArgumentsUtil.ConvertToArgumentReference(parameters));
57 return m_addOnMethod;
60 public EasyMethod CreateRemoveOnMethod(MethodAttributes atts, params Type[] parameters)
62 if (m_removeOnMethod == null)
64 m_removeOnMethod =
65 new EasyMethod(m_maintype, "remove_" + Name, atts, new ReturnReferenceExpression(typeof(void)), ArgumentsUtil.ConvertToArgumentReference(parameters));
68 return m_removeOnMethod;
71 #region IEasyMember Members
73 public void Generate()
75 if (m_addOnMethod != null)
77 m_addOnMethod.Generate();
78 m_builder.SetAddOnMethod(m_addOnMethod.MethodBuilder);
81 if (m_removeOnMethod != null)
83 m_removeOnMethod.Generate();
84 m_builder.SetRemoveOnMethod(m_removeOnMethod.MethodBuilder);
88 public void EnsureValidCodeBlock()
90 if (m_addOnMethod != null)
92 m_addOnMethod.EnsureValidCodeBlock();
95 if (m_removeOnMethod != null)
97 m_removeOnMethod.EnsureValidCodeBlock();
101 public MethodBase Member
103 get { return null; }
106 public Type ReturnType
108 get { throw new Exception("TBD"); }
111 #endregion