Simple impl to MockRailsEngineContext.Url
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy / Builder / CodeBuilder / EasyMethod.cs
blobf3472440abf210d82dcec6ef9ac9a7830de56d04
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.SimpleAST;
22 using Castle.DynamicProxy.Builder.CodeBuilder.Utils;
24 /// <summary>
25 /// Summary description for EasyMethod.
26 /// </summary>
27 [CLSCompliant(false)]
28 public class EasyMethod : IEasyMember
30 protected MethodBuilder _builder;
31 protected ArgumentReference[] _arguments;
33 private MethodCodeBuilder _codebuilder;
34 private AbstractEasyType _maintype;
36 internal EasyMethod( AbstractEasyType maintype, String name,
37 ReturnReferenceExpression returnRef, params ArgumentReference[] arguments ) :
38 this(maintype, name,
39 MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.Public,
40 returnRef, arguments)
44 internal EasyMethod( AbstractEasyType maintype, String name,
45 MethodAttributes attrs,
46 ReturnReferenceExpression returnRef, params ArgumentReference[] arguments )
48 _maintype = maintype;
49 _arguments = arguments;
51 Type returnType = returnRef.Type;
52 Type[] args = ArgumentsUtil.InitializeAndConvert( arguments );
54 _builder = maintype.TypeBuilder.DefineMethod( name, attrs,
55 returnType, args );
58 protected internal EasyMethod()
62 public virtual MethodCodeBuilder CodeBuilder
64 get
66 if (_codebuilder == null)
68 _codebuilder = new MethodCodeBuilder(
69 _maintype.BaseType, _builder, _builder.GetILGenerator() );
71 return _codebuilder;
75 public ArgumentReference[] Arguments
77 get { return _arguments; }
80 internal MethodBuilder MethodBuilder
82 get { return _builder; }
85 public Type ReturnType
87 get { return _builder.ReturnType; }
90 public MethodBase Member
92 get { return _builder; }
95 public virtual void Generate()
97 _codebuilder.Generate(this, _builder.GetILGenerator());
100 public virtual void EnsureValidCodeBlock()
102 if (CodeBuilder.IsEmpty)
104 CodeBuilder.AddStatement( new NopStatement() );
105 CodeBuilder.AddStatement( new ReturnStatement() );
109 public void DefineParameters(ParameterInfo[] info)
111 foreach (ParameterInfo parameterInfo in info)
113 _builder.DefineParameter(parameterInfo.Position+1,parameterInfo.Attributes, parameterInfo.Name);