nicko       2004/10/01 14:02:16

  Modified:    src/Config PluginAttribute.cs
               src/Core CompactRepositorySelector.cs
                        DefaultRepositorySelector.cs
               src/Repository/Hierarchy XmlHierarchyConfigurator.cs
               src/Util OptionConverter.cs PatternParser.cs
               src/Util/TypeConverters ConverterRegistry.cs
  Log:
  Replaced all type.GetConstructor().Invoke() with EmptryTypes with 
Activator.CreateInstance
  
  Revision  Changes    Path
  1.4       +1 -1      logging-log4net/src/Config/PluginAttribute.cs
  
  Index: PluginAttribute.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Config/PluginAttribute.cs,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PluginAttribute.cs        21 May 2004 22:15:32 -0000      1.3
  +++ PluginAttribute.cs        1 Oct 2004 21:02:16 -0000       1.4
  @@ -91,7 +91,7 @@
                        }
   
                        // Create an instance of the plugin using the default 
constructor
  -                     IPlugin plugin = (IPlugin) 
pluginType.GetConstructor(SystemInfo.EmptyTypes).Invoke(BindingFlags.Public | 
BindingFlags.Instance, null, new object[0], CultureInfo.InvariantCulture);
  +                     IPlugin plugin = 
(IPlugin)Activator.CreateInstance(pluginType);
   
                        return plugin;
                }
  
  
  
  1.6       +1 -1      logging-log4net/src/Core/CompactRepositorySelector.cs
  
  Index: CompactRepositorySelector.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Core/CompactRepositorySelector.cs,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CompactRepositorySelector.cs      9 Jun 2004 08:03:41 -0000       1.5
  +++ CompactRepositorySelector.cs      1 Oct 2004 21:02:16 -0000       1.6
  @@ -195,7 +195,7 @@
                                        
LogLog.Debug("DefaultRepositorySelector: Creating repository ["+repository+"] 
using type ["+repositoryType+"]");
   
                                        // Call the no arg constructor for the 
repositoryType
  -                                     rep = 
(ILoggerRepository)repositoryType.GetConstructor(SystemInfo.EmptyTypes).Invoke(null);
  +                                     rep = 
(ILoggerRepository)Activator.CreateInstance(repositoryType);
   
                                        // Set the name of the repository
                                        rep.Name = repository;
  
  
  
  1.8       +1 -1      logging-log4net/src/Core/DefaultRepositorySelector.cs
  
  Index: DefaultRepositorySelector.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Core/DefaultRepositorySelector.cs,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultRepositorySelector.cs      9 Jun 2004 08:03:41 -0000       1.7
  +++ DefaultRepositorySelector.cs      1 Oct 2004 21:02:16 -0000       1.8
  @@ -365,7 +365,7 @@
                                                
LogLog.Debug("DefaultRepositorySelector: Creating repository [" + repository + 
"] using type [" + repositoryType + "]");
   
                                                // Call the no arg constructor 
for the repositoryType
  -                                             rep = (ILoggerRepository) 
repositoryType.GetConstructor(SystemInfo.EmptyTypes).Invoke(BindingFlags.Public 
| BindingFlags.Instance, null, new object[0], CultureInfo.InvariantCulture);
  +                                             rep = 
(ILoggerRepository)Activator.CreateInstance(repositoryType);
   
                                                // Set the name of the 
repository
                                                rep.Name = repository;
  
  
  
  1.11      +8 -8      
logging-log4net/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs
  
  Index: XmlHierarchyConfigurator.cs
  ===================================================================
  RCS file: 
/home/cvs/logging-log4net/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XmlHierarchyConfigurator.cs       10 Sep 2004 18:54:14 -0000      1.10
  +++ XmlHierarchyConfigurator.cs       1 Oct 2004 21:02:16 -0000       1.11
  @@ -260,7 +260,7 @@
                        LogLog.Debug("XmlConfigurator: Loading Appender [" + 
appenderName + "] type: [" + typeName + "]");
                        try 
                        {
  -                             IAppender appender = 
(IAppender)SystemInfo.GetTypeFromString(typeName, true, 
true).GetConstructor(SystemInfo.EmptyTypes).Invoke(BindingFlags.Public | 
BindingFlags.Instance, null, new object[0], CultureInfo.InvariantCulture);
  +                             IAppender appender = 
(IAppender)Activator.CreateInstance(SystemInfo.GetTypeFromString(typeName, 
true, true));
                                appender.Name = appenderName;
   
                                foreach (XmlNode currentNode in 
appenderElement.ChildNodes)
  @@ -793,15 +793,15 @@
                        }
   
                        // Look for the default constructor
  -                     ConstructorInfo constInfo = 
objectType.GetConstructor(SystemInfo.EmptyTypes);
  -                     if (constInfo == null)
  +                     object createdObject = null;
  +                     try
                        {
  -                             LogLog.Error("XmlConfigurator: Failed to find 
default constructor for type [" + objectType.FullName + "]");
  -                             return null;
  +                             createdObject = 
Activator.CreateInstance(objectType);
  +                     }
  +                     catch(Exception createInstanceEx)
  +                     {
  +                             LogLog.Error("XmlConfigurator: Failed to 
construct object of type [" + objectType.FullName + "] Exception: 
"+createInstanceEx.ToString());
                        }
  -
  -                     // Call the constructor
  -                     object createdObject = 
constInfo.Invoke(BindingFlags.Public | BindingFlags.Instance, null, new 
object[0], CultureInfo.InvariantCulture);
   
                        // Set any params on object
                        foreach (XmlNode currentNode in element.ChildNodes)
  
  
  
  1.8       +1 -1      logging-log4net/src/Util/OptionConverter.cs
  
  Index: OptionConverter.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Util/OptionConverter.cs,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- OptionConverter.cs        10 Sep 2004 18:54:14 -0000      1.7
  +++ OptionConverter.cs        1 Oct 2004 21:02:16 -0000       1.8
  @@ -448,7 +448,7 @@
                                                LogLog.Error("OptionConverter: 
A [" + className + "] object is not assignable to a [" + superClass.FullName + 
"] variable.");
                                                return defaultValue;      
                                        }
  -                                     return 
classObj.GetConstructor(SystemInfo.EmptyTypes).Invoke(BindingFlags.Public | 
BindingFlags.Instance, null, new object[0], CultureInfo.InvariantCulture);
  +                                     return 
Activator.CreateInstance(classObj);
                                }
                                catch (Exception e) 
                                {
  
  
  
  1.4       +17 -17    logging-log4net/src/Util/PatternParser.cs
  
  Index: PatternParser.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Util/PatternParser.cs,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PatternParser.cs  23 Feb 2004 03:18:04 -0000      1.3
  +++ PatternParser.cs  1 Oct 2004 21:02:16 -0000       1.4
  @@ -295,27 +295,27 @@
                        else
                        {
                                // Create the pattern converter
  -                             ConstructorInfo constructor = 
converterType.GetConstructor(SystemInfo.EmptyTypes);
  -                             if (constructor == null)
  -                             {
  -                                     LogLog.Error("PatternParser: Converter 
Type ["+converterType.FullName+"] does not have a default constructor.");
  +                             PatternConverter pc = null;
  +                             try
  +                             {
  +                                     pc = 
(PatternConverter)Activator.CreateInstance(converterType);
                                }
  -                             else
  +                             catch(Exception createInstanceEx)
                                {
  -                                     PatternConverter pc = 
(PatternConverter)constructor.Invoke(BindingFlags.Public | 
BindingFlags.Instance, null, new object[0], CultureInfo.InvariantCulture);
  -
  -                                     // formattingInfo variable is an 
instance variable, occasionally reset 
  -                                     // and used over and over again
  -                                     pc.FormattingInfo = formattingInfo;
  -                                     pc.Option = option;
  -
  -                                     if (pc is IOptionHandler)
  -                                     {
  -                                             
((IOptionHandler)pc).ActivateOptions();
  -                                     }
  +                                     LogLog.Error("PatternParser: Failed to 
create instance of Type ["+converterType.FullName+"] using default constructor. 
Exception: "+createInstanceEx.ToString());
  +                             }
  +
  +                             // formattingInfo variable is an instance 
variable, occasionally reset 
  +                             // and used over and over again
  +                             pc.FormattingInfo = formattingInfo;
  +                             pc.Option = option;
   
  -                                     AddConverter(pc);
  +                             if (pc is IOptionHandler)
  +                             {
  +                                     ((IOptionHandler)pc).ActivateOptions();
                                }
  +
  +                             AddConverter(pc);
                        }
                }
   
  
  
  
  1.6       +1 -5      
logging-log4net/src/Util/TypeConverters/ConverterRegistry.cs
  
  Index: ConverterRegistry.cs
  ===================================================================
  RCS file: 
/home/cvs/logging-log4net/src/Util/TypeConverters/ConverterRegistry.cs,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ConverterRegistry.cs      19 Aug 2004 21:19:52 -0000      1.5
  +++ ConverterRegistry.cs      1 Oct 2004 21:02:16 -0000       1.6
  @@ -201,11 +201,7 @@
                                if 
(typeof(IConvertFrom).IsAssignableFrom(converterType) || 
typeof(IConvertTo).IsAssignableFrom(converterType))
                                {
                                        // Create the type converter
  -                                     ConstructorInfo ci = 
converterType.GetConstructor(log4net.Util.SystemInfo.EmptyTypes);
  -                                     if (ci != null)
  -                                     {
  -                                             return 
ci.Invoke(BindingFlags.Public | BindingFlags.Instance, null, new object[0], 
CultureInfo.InvariantCulture);
  -                                     }
  +                                     return 
Activator.CreateInstance(converterType);
                                }
                        }
                        return null;
  
  
  

Reply via email to