nicko       2004/09/09 11:56:53

  Modified:    src/Repository/Hierarchy XmlHierarchyConfigurator.cs
  Log:
  Added support for using a TypeConverter to convert from the explicitly 
specified type to the actual required property type
  
  Revision  Changes    Path
  1.9       +23 -1     
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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XmlHierarchyConfigurator.cs       19 Aug 2004 21:31:09 -0000      1.8
  +++ XmlHierarchyConfigurator.cs       9 Sep 2004 18:56:53 -0000       1.9
  @@ -553,6 +553,8 @@
                                        }
   #endif
   
  +                                     Type parsedObjectConversionTargetType = 
null;
  +
                                        // Check if a specific subtype is 
specified on the element using the 'type' attribute
                                        string subTypeString = 
element.GetAttribute(TYPE_ATTR);
                                        if (subTypeString != null && 
subTypeString.Length > 0)
  @@ -566,7 +568,19 @@
   
                                                        if 
(!propertyType.IsAssignableFrom(subType))
                                                        {
  -                                                             
LogLog.Error("XmlConfigurator: Subtype ["+subType.FullName+"] set on ["+name+"] 
is not a subclass of property type ["+propertyType.FullName+"]");
  +                                                             // Check if 
there is an appropriate type converter
  +                                                             if 
(OptionConverter.CanConvertTypeTo(subType, propertyType))
  +                                                             {
  +                                                                     // Must 
reconvert to real property type
  +                                                                     
parsedObjectConversionTargetType = propertyType;
  +
  +                                                                     // Use 
sub type as intermediary type
  +                                                                     
propertyType = subType;
  +                                                             }
  +                                                             else
  +                                                             {
  +                                                                     
LogLog.Error("XmlConfigurator: Subtype ["+subType.FullName+"] set on ["+name+"] 
is not a subclass of property type ["+propertyType.FullName+"] and there are no 
acceptable type conversions.");
  +                                                             }
                                                        }
                                                        else
                                                        {
  @@ -585,6 +599,14 @@
                                        // to pass to this property.
   
                                        object convertedValue = 
ConvertStringTo(propertyType, propertyValue);
  +                                     
  +                                     // Check if we need to do an additional 
conversion
  +                                     if (convertedValue != null && 
parsedObjectConversionTargetType != null)
  +                                     {
  +                                             LogLog.Debug("XmlConfigurator: 
Performing additional conversion of value from [" + 
convertedValue.GetType().Name + "] to [" + 
parsedObjectConversionTargetType.Name + "]");
  +                                             convertedValue = 
OptionConverter.ConvertTypeTo(convertedValue, parsedObjectConversionTargetType);
  +                                     }
  +
                                        if (convertedValue != null)
                                        {
                                                if (propInfo != null)
  
  
  

Reply via email to