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
.Core
.Configuration
18 using System
.Collections
.Specialized
;
21 /// This is an abstract <see cref="IConfiguration"/> implementation
22 /// that deals with methods that can be abstracted away
23 /// from underlying implementations.
26 /// <para><b>AbstractConfiguration</b> makes easier to implementers
27 /// to create a new version of <see cref="IConfiguration"/></para>
30 public abstract class AbstractConfiguration
: IConfiguration
32 protected String internalName
;
33 protected String internalValue
;
34 private NameValueCollection attributes
= new NameValueCollection();
35 private ConfigurationCollection children
= new ConfigurationCollection();
38 /// Gets the name of the <see cref="IConfiguration"/>.
41 /// The Name of the <see cref="IConfiguration"/>.
43 public virtual String Name
45 get { return internalName; }
49 /// Gets the value of <see cref="IConfiguration"/>.
52 /// The Value of the <see cref="IConfiguration"/>.
54 public virtual String Value
56 get { return internalValue; }
60 /// Gets all child nodes.
62 /// <value>The <see cref="ConfigurationCollection"/> of child nodes.</value>
63 public virtual ConfigurationCollection Children
65 get { return children; }
69 /// Gets node attributes.
72 /// All attributes of the node.
74 public virtual NameValueCollection Attributes
76 get { return attributes; }
80 /// Gets the value of the node and converts it
81 /// into specified <see cref="System.Type"/>.
83 /// <param name="type">The <see cref="System.Type"/></param>
84 /// <param name="defaultValue">
85 /// The Default value returned if the convertion fails.
87 /// <returns>The Value converted into the specified type.</returns>
88 public virtual object GetValue(Type type
, object defaultValue
)
92 return Convert
.ChangeType(Value
, type
);