Simple impl to MockRailsEngineContext.Url
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy / Builder / CodeBuilder / EasyConstructor.cs
blobf0fb52ad200a106d265494aa9a10450d23a3b7c5
1 // Copyright 2004-2007 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.Utils;
22 using Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST;
24 /// <summary>
25 /// Summary description for EasyConstructor.
26 /// </summary>
27 [CLSCompliant(false)]
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 )
36 _maintype = maintype;
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
50 get
52 if (_codebuilder == null)
54 _codebuilder = new ConstructorCodeBuilder(
55 _maintype.BaseType, _builder.GetILGenerator() );
57 return _codebuilder;
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() );