logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: Weird idea for passing multiple Option values into PatternConverters
Date Fri, 07 Oct 2005 18:08:26 GMT
I think I like the use of named properties better than positional ones.
We can use reflection to set the property values as well, makes it easy
for the implementer and more descriptive to the user.

The Option property would remain the full text of the whole argument to
support backward compatibility.

Using named properties you would have something like:

%property{key=InvoiceAmount,format=##.##}

or

%property{key='InvoiceAmount',format='##.##'}

The %property pattern converter would have 2 public read write string
properties Key and Format. We would then have to write the magic that
parsed the Option text and set the properties correctly.

Thoughts?


Nicko

> -----Original Message-----
> From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
> Sent: 06 October 2005 05:37
> To: log4net-dev@logging.apache.org
> Subject: Weird idea for passing multiple Option values into 
> PatternConverters
> 
> Classes that extend PatternConverter expose the value passed into the
> pattern:
> 
>  %foo{valuePassedIntoThePattern}
> 
> as a property called Option. If someone wants to pass in more 
> than one value they are responsible for parsing the string 
> using their own
> delimiters:
> 
>  %foo{valuePassedIntoThePattern,secondValue,thirdValue}
>  %foo{valuePassedIntoThePattern:secondValue:thirdValue}
>  %foo{valuePassedIntoThePattern|secondValue|thirdValue}
> 
> Perhaps we could use the following notation to help the user 
> deal with multiple values being passed in:
> 
>  %foo{valuePassedIntoThePattern}{secondValue}{thirdValue}
> 
> We would introduce another property on PatternConverter 
> called Options which would be a string array of all the 
> values passed into the pattern. The index would be the 
> matching index of the value passed in.
> We would still keep Option for quick reference:
> 
>  public virtual string Option
>  {
>   get { return m_option; }
>   set { m_option = value; }
>  }
>  public virtual string[] Options
>  {
>   get { return m_options; }
>   set { m_options = value; }
>  }
> 
>  Assert.AreEqual(Options, Options[0]);
> 
> This would make it very easy to write a 
> FormatPropertyPatternConverter that accepted a format as an 
> optional 2nd parameter:
> 
>  %property{InvoiceAmount}{##.##}
> 
> Deep within PatternConverter you could replace this code:
> 
>  writer.Write( value.ToString() );
> 
> with this:
> 
>  if (values.Count == 2)
>  {
>   writer.Write(values[1], values[0] );
>  }
>  else
>  {
>   writer.Write( values[0] );
>  }
> 
> Comments?
> 
> - Ron
> 
> 

Mime
View raw message