Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Core / Castle.Core / Model / Configuration / AbstractConfiguration.cs
blobaba40ce7e2b8a597bb517f8cb18b67cb7e8f7119
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.Core.Configuration
17 using System;
18 using System.Collections.Specialized;
20 /// <summary>
21 /// This is an abstract <see cref="IConfiguration"/> implementation
22 /// that deals with methods that can be abstracted away
23 /// from underlying implementations.
24 /// </summary>
25 /// <remarks>
26 /// <para><b>AbstractConfiguration</b> makes easier to implementers
27 /// to create a new version of <see cref="IConfiguration"/></para>
28 /// </remarks>
29 [Serializable]
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();
37 /// <summary>
38 /// Gets the name of the <see cref="IConfiguration"/>.
39 /// </summary>
40 /// <value>
41 /// The Name of the <see cref="IConfiguration"/>.
42 /// </value>
43 public virtual String Name
45 get { return internalName; }
48 /// <summary>
49 /// Gets the value of <see cref="IConfiguration"/>.
50 /// </summary>
51 /// <value>
52 /// The Value of the <see cref="IConfiguration"/>.
53 /// </value>
54 public virtual String Value
56 get { return internalValue; }
59 /// <summary>
60 /// Gets all child nodes.
61 /// </summary>
62 /// <value>The <see cref="ConfigurationCollection"/> of child nodes.</value>
63 public virtual ConfigurationCollection Children
65 get { return children; }
68 /// <summary>
69 /// Gets node attributes.
70 /// </summary>
71 /// <value>
72 /// All attributes of the node.
73 /// </value>
74 public virtual NameValueCollection Attributes
76 get { return attributes; }
79 /// <summary>
80 /// Gets the value of the node and converts it
81 /// into specified <see cref="System.Type"/>.
82 /// </summary>
83 /// <param name="type">The <see cref="System.Type"/></param>
84 /// <param name="defaultValue">
85 /// The Default value returned if the convertion fails.
86 /// </param>
87 /// <returns>The Value converted into the specified type.</returns>
88 public virtual object GetValue(Type type, object defaultValue)
90 try
92 return Convert.ChangeType(Value, type);
94 catch(Exception)
96 return defaultValue;