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 EasyProperty.
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
)
39 _builder
= maintype
.TypeBuilder
.DefineProperty(
40 name
, PropertyAttributes
.None
, returnType
, new Type
[0]);
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)
61 _getMethod
= new EasyMethod(_maintype
, "get_" + _builder
.Name
,
63 new ReturnReferenceExpression(ReturnType
),
64 ArgumentsUtil
.ConvertToArgumentReference(parameters
));
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)
82 _setMethod
= new EasyMethod(_maintype
, "set_" + _builder
.Name
,
84 new ReturnReferenceExpression(typeof(void)),
85 ArgumentsUtil
.ConvertToArgumentReference(parameters
));
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
125 public Type ReturnType
127 get { return _builder.PropertyType; }
130 public ParameterInfo
[] IndexParameters
132 get { return _indexParameters; }
133 set { _indexParameters = value; }