1
#region Copyright & License
3
// Copyright 2001-2005 The Apache Software Foundation
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
9
// http://www.apache.org/licenses/LICENSE-2.0
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.
19
// .NET Compact Framework 1.0 has no support for reading assembly attributes
23
using System.Globalization;
24
using System.Reflection;
30
namespace log4net.Config
33
/// Assembly level attribute that specifies a plugin to attach to
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.
43
/// <author>Nicko Cadell</author>
44
/// <author>Gert Driesen</author>
45
[AttributeUsage(AttributeTargets.Assembly,AllowMultiple=true)]
47
public sealed class PluginAttribute : Attribute, IPluginFactory
49
#region Public Instance Constructors
52
/// Initializes a new instance of the <see cref="PluginAttribute" /> class
53
/// with the specified type.
55
/// <param name="typeName">The type name of plugin to create.</param>
58
/// Create the attribute with the plugin type specified.
61
/// Where possible use the constructor that takes a <see cref="System.Type"/>.
64
public PluginAttribute(string typeName)
66
m_typeName = typeName;
70
/// Initializes a new instance of the <see cref="PluginAttribute" /> class
71
/// with the specified type.
73
/// <param name="type">The type of plugin to create.</param>
76
/// Create the attribute with the plugin type specified.
79
public PluginAttribute(Type type)
84
#endregion Public Instance Constructors
86
#region Public Instance Properties
89
/// Gets or sets the type for the plugin.
92
/// The type for the plugin.
96
/// The type for the plugin.
101
get { return m_type; }
102
set { m_type = value ; }
106
/// Gets or sets the type name for the plugin.
109
/// The type name for the plugin.
113
/// The type name for the plugin.
116
/// Where possible use the <see cref="Type"/> property instead.
119
public string TypeName
121
get { return m_typeName; }
122
set { m_typeName = value ; }
125
#endregion Public Instance Properties
127
#region Implementation of IPluginFactory
130
/// Creates the plugin object defined by this attribute.
134
/// Creates the instance of the <see cref="IPlugin"/> object as
135
/// specified by this attribute.
138
/// <returns>The plugin object.</returns>
139
public IPlugin CreatePlugin()
141
Type pluginType = m_type;
144
// Get the plugin object type from the string type name
145
pluginType = SystemInfo.GetTypeFromString(m_typeName, true, true);
148
// Check that the type is a plugin
149
if (!(typeof(IPlugin).IsAssignableFrom(pluginType)))
151
throw new LogException("Plugin type [" + pluginType.FullName + "] does not implement the log4net.IPlugin interface");
154
// Create an instance of the plugin using the default constructor
155
IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginType);
160
#endregion Implementation of IPluginFactory
162
#region Override implementation of Object
165
/// Returns a representation of the properties of this object.
169
/// Overrides base class <see cref="Object.ToString()" /> method to
170
/// return a representation of the properties of this object.
173
/// <returns>A representation of the properties of this object</returns>
174
override public string ToString()
178
return "PluginAttribute[Type=" + m_type.FullName + "]";
180
return "PluginAttribute[Type=" + m_typeName + "]";
183
#endregion Override implementation of Object
185
#region Private Instance Fields
187
private string m_typeName = null;
188
private Type m_type = null;
190
#endregion Private Instance Fields
b'\\ No newline at end of file'