1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Reflection
;
19 using System
.Reflection
.Emit
;
21 using Castle
.DynamicProxy
.Builder
.CodeBuilder
.SimpleAST
;
22 using Castle
.DynamicProxy
.Builder
.CodeBuilder
.Utils
;
25 /// Summary description for EasyEvent.
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
)
39 m_maintype
= maintype
;
40 m_builder
= maintype
.TypeBuilder
.DefineEvent(
41 name
, EventAttributes
.None
, eventHandlerType
);
46 get { return m_name; }
49 public EasyMethod
CreateAddOnMethod(MethodAttributes atts
, params Type
[] parameters
)
51 if (m_addOnMethod
== null)
54 new EasyMethod(m_maintype
, "add_" + Name
, atts
, new ReturnReferenceExpression(typeof(void)), ArgumentsUtil
.ConvertToArgumentReference(parameters
));
60 public EasyMethod
CreateRemoveOnMethod(MethodAttributes atts
, params Type
[] parameters
)
62 if (m_removeOnMethod
== null)
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
106 public Type ReturnType
108 get { throw new Exception("TBD"); }