nicko 2005/08/24 06:20:45 Modified: src/Config PluginAttribute.cs Log: Fix for LOG4NET-45. Added constructor and property to take plugin type as a Type Revision Changes Path 1.7 +56 -9 logging-log4net/src/Config/PluginAttribute.cs Index: PluginAttribute.cs =================================================================== RCS file: /home/cvs/logging-log4net/src/Config/PluginAttribute.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PluginAttribute.cs 17 Jan 2005 20:18:42 -0000 1.6 +++ PluginAttribute.cs 24 Aug 2005 13:20:45 -0000 1.7 @@ -52,13 +52,31 @@ /// Initializes a new instance of the <see cref="PluginAttribute" /> class
/// with the specified type. /// </summary> + /// <param name="typeName">The type name of plugin to create.</param> + /// <remarks> + /// <para> + /// Create the attribute with the plugin type specified. + /// </para> + /// <para> + /// Where possible use the constructor that takes a <see cref="System.Type"/>. + /// </para> + /// </remarks> + public PluginAttribute(string typeName) + { + m_typeName = typeName; + } + + /// <summary> + /// Initializes a new instance of the <see cref="PluginAttribute" /> class + /// with the specified type. + /// </summary> /// <param name="type">The type of plugin to create.</param> /// <remarks> /// <para> /// Create the attribute with the plugin type specified. /// </para> /// </remarks> - public PluginAttribute(string type) + public PluginAttribute(Type type) { m_type = type; } @@ -68,6 +86,23 @@ #region Public Instance Properties /// <summary> + /// Gets or sets the type for the plugin. + /// </summary> + /// <value> + /// The type for the plugin. + /// </value> + /// <remarks> + /// <para> + /// The type for the plugin. + /// </para> + /// </remarks> + public Type Type + { + get { return m_type; } + set { m_type = value ; } + } + + /// <summary> /// Gets or sets the type name for the plugin. /// </summary> /// <value> @@ -77,11 +112,14 @@ /// <para> /// The type name for the plugin. /// </para> + /// <para> + /// Where possible use the <see cref="Type"/> property instead. + /// </para> /// </remarks> - public string Type + public string TypeName { - get { return m_type; } - set { m_type = value ; } + get { return m_typeName; } + set { m_typeName = value ; } } #endregion Public Instance Properties @@ -100,13 +138,17 @@ /// <returns>The plugin object.</returns> public IPlugin CreatePlugin() { - // Get the plugin object type - System.Type pluginType = SystemInfo.GetTypeFromString(this.Type, true, true); + Type pluginType = m_type; + if (m_type == null) + { + // Get the plugin object type from the string type name + pluginType = SystemInfo.GetTypeFromString(m_typeName, true, true); + } // Check that the type is a plugin if (!(typeof(IPlugin).IsAssignableFrom(pluginType))) { - throw new LogException("Plugin type [" + this.Type + "] does not implement log4net.IPlugin interface"); + throw new LogException("Plugin type [" + pluginType.FullName + "] does not implement the log4net.IPlugin interface"); } // Create an instance of the plugin using the default constructor @@ -131,14 +173,19 @@ /// <returns>A representation of the properties of this object</returns> override public string ToString() { - return "PluginAttribute[Type=" + this.Type + "]"; + if (m_type != null) + { + return "PluginAttribute[Type=" + m_type.FullName + "]"; + } + return "PluginAttribute[Type=" + m_typeName + "]"; } #endregion Override implementation of Object #region Private Instance Fields - private string m_type = null; + private string m_typeName = null; + private Type m_type = null; #endregion Private Instance Fields }