~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/Simias.log4net/src/Config/.svn/text-base/PluginAttribute.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#region Copyright & License
2
 
//
3
 
// Copyright 2001-2005 The Apache Software Foundation
4
 
//
5
 
// Licensed under the Apache License, Version 2.0 (the "License");
6
 
// you may not use this file except in compliance with the License.
7
 
// You may obtain a copy of the License at
8
 
//
9
 
// http://www.apache.org/licenses/LICENSE-2.0
10
 
//
11
 
// Unless required by applicable law or agreed to in writing, software
12
 
// distributed under the License is distributed on an "AS IS" BASIS,
13
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
// See the License for the specific language governing permissions and
15
 
// limitations under the License.
16
 
//
17
 
#endregion
18
 
 
19
 
// .NET Compact Framework 1.0 has no support for reading assembly attributes
20
 
#if !NETCF
21
 
 
22
 
using System;
23
 
using System.Globalization;
24
 
using System.Reflection;
25
 
 
26
 
using log4net.Core;
27
 
using log4net.Util;
28
 
using log4net.Plugin;
29
 
 
30
 
namespace log4net.Config
31
 
{
32
 
        /// <summary>
33
 
        /// Assembly level attribute that specifies a plugin to attach to 
34
 
        /// the repository.
35
 
        /// </summary>
36
 
        /// <remarks>
37
 
        /// <para>
38
 
        /// Specifies the type of a plugin to create and attach to the
39
 
        /// assembly's repository. The plugin type must implement the
40
 
        /// <see cref="IPlugin"/> interface.
41
 
        /// </para>
42
 
        /// </remarks>
43
 
        /// <author>Nicko Cadell</author>
44
 
        /// <author>Gert Driesen</author>
45
 
        [AttributeUsage(AttributeTargets.Assembly,AllowMultiple=true)]
46
 
        [Serializable]
47
 
        public sealed class PluginAttribute : Attribute, IPluginFactory
48
 
        {
49
 
                #region Public Instance Constructors
50
 
 
51
 
                /// <summary>
52
 
                /// Initializes a new instance of the <see cref="PluginAttribute" /> class
53
 
                /// with the specified type.
54
 
                /// </summary>
55
 
                /// <param name="typeName">The type name of plugin to create.</param>
56
 
                /// <remarks>
57
 
                /// <para>
58
 
                /// Create the attribute with the plugin type specified.
59
 
                /// </para>
60
 
                /// <para>
61
 
                /// Where possible use the constructor that takes a <see cref="System.Type"/>.
62
 
                /// </para>
63
 
                /// </remarks>
64
 
                public PluginAttribute(string typeName)
65
 
                {
66
 
                        m_typeName = typeName;
67
 
                }
68
 
 
69
 
                /// <summary>
70
 
                /// Initializes a new instance of the <see cref="PluginAttribute" /> class
71
 
                /// with the specified type.
72
 
                /// </summary>
73
 
                /// <param name="type">The type of plugin to create.</param>
74
 
                /// <remarks>
75
 
                /// <para>
76
 
                /// Create the attribute with the plugin type specified.
77
 
                /// </para>
78
 
                /// </remarks>
79
 
                public PluginAttribute(Type type)
80
 
                {
81
 
                        m_type = type;
82
 
                }
83
 
 
84
 
                #endregion Public Instance Constructors
85
 
 
86
 
                #region Public Instance Properties
87
 
 
88
 
                /// <summary>
89
 
                /// Gets or sets the type for the plugin.
90
 
                /// </summary>
91
 
                /// <value>
92
 
                /// The type for the plugin.
93
 
                /// </value>
94
 
                /// <remarks>
95
 
                /// <para>
96
 
                /// The type for the plugin.
97
 
                /// </para>
98
 
                /// </remarks>
99
 
                public Type Type
100
 
                {
101
 
                        get { return m_type; }
102
 
                        set { m_type = value ; }
103
 
                }
104
 
 
105
 
                /// <summary>
106
 
                /// Gets or sets the type name for the plugin.
107
 
                /// </summary>
108
 
                /// <value>
109
 
                /// The type name for the plugin.
110
 
                /// </value>
111
 
                /// <remarks>
112
 
                /// <para>
113
 
                /// The type name for the plugin.
114
 
                /// </para>
115
 
                /// <para>
116
 
                /// Where possible use the <see cref="Type"/> property instead.
117
 
                /// </para>
118
 
                /// </remarks>
119
 
                public string TypeName
120
 
                {
121
 
                        get { return m_typeName; }
122
 
                        set { m_typeName = value ; }
123
 
                }
124
 
 
125
 
                #endregion Public Instance Properties
126
 
 
127
 
                #region Implementation of IPluginFactory
128
 
 
129
 
                /// <summary>
130
 
                /// Creates the plugin object defined by this attribute.
131
 
                /// </summary>
132
 
                /// <remarks>
133
 
                /// <para>
134
 
                /// Creates the instance of the <see cref="IPlugin"/> object as 
135
 
                /// specified by this attribute.
136
 
                /// </para>
137
 
                /// </remarks>
138
 
                /// <returns>The plugin object.</returns>
139
 
                public IPlugin CreatePlugin()
140
 
                {
141
 
                        Type pluginType = m_type;
142
 
                        if (m_type == null)
143
 
                        {
144
 
                                // Get the plugin object type from the string type name
145
 
                                pluginType = SystemInfo.GetTypeFromString(m_typeName, true, true);
146
 
                        }
147
 
 
148
 
                        // Check that the type is a plugin
149
 
                        if (!(typeof(IPlugin).IsAssignableFrom(pluginType)))
150
 
                        {
151
 
                                throw new LogException("Plugin type [" + pluginType.FullName + "] does not implement the log4net.IPlugin interface");
152
 
                        }
153
 
 
154
 
                        // Create an instance of the plugin using the default constructor
155
 
                        IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginType);
156
 
 
157
 
                        return plugin;
158
 
                }
159
 
 
160
 
                #endregion Implementation of IPluginFactory
161
 
 
162
 
                #region Override implementation of Object
163
 
 
164
 
                /// <summary>
165
 
                /// Returns a representation of the properties of this object.
166
 
                /// </summary>
167
 
                /// <remarks>
168
 
                /// <para>
169
 
                /// Overrides base class <see cref="Object.ToString()" /> method to 
170
 
                /// return a representation of the properties of this object.
171
 
                /// </para>
172
 
                /// </remarks>
173
 
                /// <returns>A representation of the properties of this object</returns>
174
 
                override public string ToString()
175
 
                {
176
 
                        if (m_type != null)
177
 
                        {
178
 
                                return "PluginAttribute[Type=" + m_type.FullName + "]";
179
 
                        }
180
 
                        return "PluginAttribute[Type=" + m_typeName + "]";
181
 
                }
182
 
 
183
 
                #endregion Override implementation of Object
184
 
 
185
 
                #region Private Instance Fields
186
 
 
187
 
                private string m_typeName = null;
188
 
                private Type m_type = null;
189
 
 
190
 
                #endregion Private Instance Fields
191
 
        }
192
 
}
193
 
 
194
 
#endif // !NETCF
 
 
b'\\ No newline at end of file'