1 // Copyright 2004-2008 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
;
21 /// Identifies a property should be represented as a nested component.
23 [AttributeUsage(AttributeTargets
.Property
, AllowMultiple
= false, Inherited
= true)]
24 public class DictionaryComponentAttribute
:
25 DictionaryBehaviorAttribute
, IDictionaryKeyBuilder
, IDictionaryPropertyGetter
27 private String prefix
;
30 /// Applies no prefix.
34 get { return prefix == ""; }
45 /// Gets or sets the prefix.
47 /// <value>The prefix.</value>
50 get { return prefix; }
51 set { prefix = value; }
54 #region IDictionaryKeyBuilder Members
56 string IDictionaryKeyBuilder
.GetKey(IDictionary dictionary
, string key
,
57 PropertyDescriptor property
)
59 return prefix
?? key
+ "_";
64 #region IDictionaryPropertyGetter
66 object IDictionaryPropertyGetter
.GetPropertyValue(
67 IDictionaryAdapterFactory factory
, IDictionary dictionary
,
68 string key
, object storedValue
, PropertyDescriptor property
)
70 if (storedValue
== null)
72 PropertyDescriptor descriptor
=
73 new PropertyDescriptor(property
.Property
);
74 descriptor
.AddKeyBuilder(new DictionaryKeyPrefixAttribute(key
));
76 return factory
.GetAdapter(
77 property
.Property
.PropertyType
, dictionary
, descriptor
);