- Changed ReflectionBasedDictionaryAdapter to ignore calls to Remove instead of throw...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Views / Aspx / ControllerBinder / Design / StandardTarget.cs
blob88c8a060d3230eee72f81bc7e63e2c6782949868
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 #if NET
17 namespace Castle.MonoRail.Framework.Views.Aspx.Design
19 using System;
20 using System.ComponentModel;
22 /// <summary>
23 /// Pendent
24 /// </summary>
25 public class StandardTarget : ITarget
27 private readonly Type type;
28 private readonly string name;
29 private string[] propertyNames;
31 /// <summary>
32 /// Initializes a new instance of the <see cref="StandardTarget"/> class.
33 /// </summary>
34 /// <param name="name">The name.</param>
35 public StandardTarget(string name)
37 if (name == null)
39 throw new ArgumentNullException("name");
42 this.name = name;
45 /// <summary>
46 /// Initializes a new instance of the <see cref="StandardTarget"/> class.
47 /// </summary>
48 /// <param name="type">The type.</param>
49 /// <param name="name">The name.</param>
50 public StandardTarget(Type type, string name) : this(name)
52 if (type == null)
54 throw new ArgumentNullException("type");
57 this.type = type;
60 /// <summary>
61 /// Initializes a new instance of the <see cref="StandardTarget"/> class.
62 /// </summary>
63 /// <param name="instance">The instance.</param>
64 /// <param name="name">The name.</param>
65 public StandardTarget(object instance, string name) : this(name)
67 if (instance == null)
69 throw new ArgumentNullException("instance");
72 type = instance.GetType();
75 /// <summary>
76 /// Gets the property names.
77 /// </summary>
78 /// <value>The property names.</value>
79 public string[] PropertyNames
81 get
83 if (propertyNames == null)
85 propertyNames = CollectPropertyNames(type);
86 Array.Sort(propertyNames);
88 return propertyNames;
92 /// <summary>
93 /// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
94 /// </summary>
95 /// <returns>
96 /// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
97 /// </returns>
98 public override string ToString()
100 return name;
103 /// <summary>
104 /// Collects the property names.
105 /// </summary>
106 /// <param name="type">The type.</param>
107 /// <returns></returns>
108 protected virtual string[] CollectPropertyNames(Type type)
110 if (type == null) return new string[0];
112 PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(type);
114 string[] propertyDescNames = new string[properties.Count];
116 for (int i = 0; i < properties.Count; ++i)
118 propertyDescNames[i] = properties[i].Name;
121 return propertyDescNames;
126 #endif