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.
17 namespace Castle
.MonoRail
.Framework
.Views
.Aspx
.Design
20 using System
.ComponentModel
;
25 public class StandardTarget
: ITarget
27 private readonly Type type
;
28 private readonly string name
;
29 private string[] propertyNames
;
32 /// Initializes a new instance of the <see cref="StandardTarget"/> class.
34 /// <param name="name">The name.</param>
35 public StandardTarget(string name
)
39 throw new ArgumentNullException("name");
46 /// Initializes a new instance of the <see cref="StandardTarget"/> class.
48 /// <param name="type">The type.</param>
49 /// <param name="name">The name.</param>
50 public StandardTarget(Type type
, string name
) : this(name
)
54 throw new ArgumentNullException("type");
61 /// Initializes a new instance of the <see cref="StandardTarget"/> class.
63 /// <param name="instance">The instance.</param>
64 /// <param name="name">The name.</param>
65 public StandardTarget(object instance
, string name
) : this(name
)
69 throw new ArgumentNullException("instance");
72 type
= instance
.GetType();
76 /// Gets the property names.
78 /// <value>The property names.</value>
79 public string[] PropertyNames
83 if (propertyNames
== null)
85 propertyNames
= CollectPropertyNames(type
);
86 Array
.Sort(propertyNames
);
93 /// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
96 /// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
98 public override string ToString()
104 /// Collects the property names.
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
;