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
.Utils
;
22 using Castle
.DynamicProxy
.Builder
.CodeBuilder
.SimpleAST
;
25 /// Summary description for EasyConstructor.
28 public class EasyConstructor
: IEasyMember
30 protected ConstructorBuilder _builder
;
31 private ConstructorCodeBuilder _codebuilder
;
32 private AbstractEasyType _maintype
;
34 internal EasyConstructor( AbstractEasyType maintype
, params ArgumentReference
[] arguments
)
38 Type
[] args
= ArgumentsUtil
.InitializeAndConvert( arguments
);
40 _builder
= maintype
.TypeBuilder
.DefineConstructor(
41 MethodAttributes
.Public
, CallingConventions
.Standard
, args
);
44 protected internal EasyConstructor()
48 public virtual ConstructorCodeBuilder CodeBuilder
52 if (_codebuilder
== null)
54 _codebuilder
= new ConstructorCodeBuilder(
55 _maintype
.BaseType
, _builder
.GetILGenerator() );
61 internal ConstructorBuilder Builder
63 get { return _builder; }
66 public MethodBase Member
68 get { return _builder; }
71 public Type ReturnType
73 get { return typeof(void); }
76 public virtual void Generate()
78 _codebuilder
.Generate(this, _builder
.GetILGenerator());
81 public virtual void EnsureValidCodeBlock()
83 if (CodeBuilder
.IsEmpty
)
85 CodeBuilder
.InvokeBaseConstructor();
86 CodeBuilder
.AddStatement( new ReturnStatement() );