Simple impl to MockRailsEngineContext.Url
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy / Builder / CodeBuilder / EasyProperty.cs
blobca7b1d594f9b1c291f5fb75ebbb1eb83880ba75f
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 EasyProperty.
26 /// </summary>
27 [CLSCompliant(false)]
28 public class EasyProperty : IEasyMember
30 private PropertyBuilder _builder;
31 private AbstractEasyType _maintype;
32 private EasyMethod _getMethod;
33 private EasyMethod _setMethod;
34 private ParameterInfo[] _indexParameters;
36 public EasyProperty(AbstractEasyType maintype, String name, Type returnType)
38 _maintype = maintype;
39 _builder = maintype.TypeBuilder.DefineProperty(
40 name, PropertyAttributes.None, returnType, new Type[0]);
43 public String Name
45 get { return _builder.Name; }
48 public EasyMethod CreateGetMethod()
50 return CreateGetMethod(
51 MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.SpecialName);
54 public EasyMethod CreateGetMethod(MethodAttributes attrs, params Type[] parameters)
56 if (_getMethod != null)
58 return _getMethod;
61 _getMethod = new EasyMethod(_maintype, "get_" + _builder.Name,
62 attrs,
63 new ReturnReferenceExpression(ReturnType),
64 ArgumentsUtil.ConvertToArgumentReference(parameters));
66 return _getMethod;
69 public EasyMethod CreateSetMethod(Type arg)
71 return CreateSetMethod(
72 MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.SpecialName, arg);
75 public EasyMethod CreateSetMethod(MethodAttributes attrs, params Type[] parameters)
77 if (_setMethod != null)
79 return _setMethod;
82 _setMethod = new EasyMethod(_maintype, "set_" + _builder.Name,
83 attrs,
84 new ReturnReferenceExpression(typeof(void)),
85 ArgumentsUtil.ConvertToArgumentReference(parameters));
87 return _setMethod;
90 #region IEasyMember Members
92 public void Generate()
94 if (_setMethod != null)
96 _setMethod.Generate();
97 _builder.SetSetMethod(_setMethod.MethodBuilder);
100 if (_getMethod != null)
102 _getMethod.Generate();
103 _builder.SetGetMethod(_getMethod.MethodBuilder);
107 public void EnsureValidCodeBlock()
109 if (_setMethod != null)
111 _setMethod.EnsureValidCodeBlock();
114 if (_getMethod != null)
116 _getMethod.EnsureValidCodeBlock();
120 public MethodBase Member
122 get { return null; }
125 public Type ReturnType
127 get { return _builder.PropertyType; }
130 public ParameterInfo[] IndexParameters
132 get { return _indexParameters; }
133 set { _indexParameters = value; }
136 #endregion