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
.Components
.DictionaryAdapter
18 using System
.Collections
;
19 using System
.ComponentModel
;
22 /// Manages conversion between property values.
24 public class DefaultPropertyGetter
: IDictionaryPropertyGetter
26 private readonly TypeConverter converter
;
29 /// Initializes a new instance of the <see cref="DefaultPropertyGetter"/> class.
31 /// <param name="converter">The converter.</param>
32 public DefaultPropertyGetter(TypeConverter converter
)
34 this.converter
= converter
;
40 public int ExecutionOrder
42 get { return int.MaxValue; }
46 /// Gets the effective dictionary value.
48 /// <param name="factory">The dictionary factory.</param>
49 /// <param name="dictionary">The dictionary.</param>
50 /// <param name="key">The key.</param>
51 /// <param name="storedValue">The stored value.</param>
52 /// <param name="property">The property.</param>
53 /// <returns>The effective property value.</returns>
54 public object GetPropertyValue(IDictionaryAdapterFactory factory
,
55 IDictionary dictionary
, string key
,
56 object storedValue
, PropertyDescriptor property
)
58 Type propertyType
= property
.PropertyType
;
60 if (storedValue
!= null && !propertyType
.IsInstanceOfType(storedValue
))
62 if (converter
!= null && converter
.CanConvertFrom(storedValue
.GetType()))
64 return converter
.ConvertFrom(storedValue
);