Added RedirectUsingNamedRoute
[castle.git] / Components / DictionaryAdapter / Castle.Components.DictionaryAdapter / Attributes / DictionaryComponentAttribute.cs
blob58f35e88fd2cd1cfa1618408208873721c85d557
1 // Copyright 2004-2008 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.Components.DictionaryAdapter
17 using System;
18 using System.Collections;
20 /// <summary>
21 /// Identifies a property should be represented as a nested component.
22 /// </summary>
23 [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
24 public class DictionaryComponentAttribute :
25 DictionaryBehaviorAttribute, IDictionaryKeyBuilder, IDictionaryPropertyGetter
27 private String prefix;
29 /// <summary>
30 /// Applies no prefix.
31 /// </summary>
32 public bool NoPrefix
34 get { return prefix == ""; }
35 set
37 if (value)
39 Prefix = "";
44 /// <summary>
45 /// Gets or sets the prefix.
46 /// </summary>
47 /// <value>The prefix.</value>
48 public string Prefix
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 + "_";
62 #endregion
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);
80 return storedValue;
83 #endregion