[Mono-dev] ConfigurationElementCollection.ThrowOnDuplicate
Atsushi Eno
atsushi at ximian.com
Mon Dec 25 11:18:23 EST 2006
Hi Kosta,
Thanks again for the hint :-) Yeah, I agree with you. I'm not sure
how "Alternate collection" should work, but the examples attached
worked similarly.
If it is a different issue to fix, and no further issue on the
changes, I'll apply the change based on your suggestion.
Atsushi Eno
Konstantin Triger wrote:
> Hi Atsushi,
>
> I think it should be like this:
>
> protected void BaseAdd (ConfigurationElement element, bool throwIfExists)
> {
> - if (throwIfExists && BaseIndexOf (element) != -1)
> - throw new ConfigurationException
> ("Duplicate element in collection");
> if (IsReadOnly ())
> throw new ConfigurationErrorsException
> ("Collection is read only.");
> + int old_index = IndexOfKey (GetElementKey
> (element));
> + if (old_index != -1) {
> + if (element.Equals(list(old_index)))
> + return;
> + if (throwIfExists)
> + throw new ConfigurationException
> ("Duplicate element in collection");
> + }
> if (IsAlternate) {
> list.Insert (inheritedLimitIndex, element);
> inheritedLimitIndex++;
>
> This is because the second argument to the BaseAdd overrides the
> ThrowOnDuplicate return value. An open question is an Alternate
> collection, since there can be several elements with same key if
> ThrowOnDuplicate return false. But it is a different issue...
>
> Regards,
> Kosta
>
>
>
> -----Original Message-----
> From: Atsushi Eno [mailto:atsushi at ximian.com]
> Sent: Fri 22/12/2006 16:09
> To: Konstantin Triger
> Cc: mono-devel-list at lists.ximian.com
> Subject: Re: [Mono-dev] ConfigurationElementCollection.ThrowOnDuplicate
>
> Hi Kosta,
>
> Thanks for the hint :-) Now I understand what ThrowOnDuplicate
> means - it rejects a different element. Therefore, current
> mono implementation has an issue that an identical element to
> one of the existing items actually raises an error.
>
> I have a patch and some standalone tests for review.
>
> Atsushi Eno
>
> Konstantin Triger wrote:
> > Hi Atsushi,
> >
> > I think the implementation of ThrowOnDuplicate is correct: it indicates
> > whether the collection throws if duplicates exist. To make this happen
> > there should be elements with same keys but different values. But I
> > think that your implementation of MySection is incorrect, it should be
> > like this:
> >
> > public class MySection : ConfigurationSection
> > {
> > [ConfigurationProperty("MyElements")]
> > public MyElementCollection MyElements
> > {
> > get { return (MyElementCollection)this["MyElements"]; }
> > }
> > }
> >
> > In addition, a cleaner implementation for MyElement would be this:
> >
> > public class MyElement : ConfigurationElement
> > {
> > [ConfigurationProperty("name", Options =
> > ConfigurationPropertyOptions.IsKey)]
> > public string Name
> > {
> > get { return (string)this["name"]; }
> > }
> > /*
> > [ConfigurationProperty("value")]
> > public string Value
> > {
> > get { return (string)this["value"]; }
> > }
> > */
> > }
> >
> > BTW, uncomment Value property and add some 'value' to one of your Foos.
> > This throws on .net (did not check on mono).
> >
> > Regards,
> > Kosta
> >
> >
> >
> > -----Original Message-----
> > From: mono-devel-list-bounces at lists.ximian.com on behalf of Atsushi Eno
> > Sent: Fri 22/12/2006 11:03
> > To: mono-devel-list at lists.ximian.com
> > Subject: [Mono-dev] ConfigurationElementCollection.ThrowOnDuplicate
> >
> > Hi,
> >
> > I have been trying to fix some web service config stuff, and
> > noticed that ConfigurationElementCollection.ThrowOnDuplicate property
> > behavior is somewhat different from .net (the attached example
> > does not raise an error on .net while mono does).
> >
> > According to the documentation, I believe that Mono behavior is
> > the correct behavior, but with this I find difficulty to fix
> > web service configuration issue, so I'm tempted to find that
> > current behavior is incorrect (and my understanding becomes wrong) ;-)
> >
> > So, does anyone have ideas on how this property works?
> >
> > Atsushi Eno
> >
>
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: t40.cs
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061226/819489db/attachment.pl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t40.exe.config
Type: application/xml
Size: 259 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061226/819489db/attachment.rdf
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: t40.exe.expected
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061226/819489db/attachment-0001.pl
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: t41.cs
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061226/819489db/attachment-0002.pl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t41.exe.config
Type: application/xml
Size: 259 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061226/819489db/attachment-0001.rdf
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: t41.exe.expected
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061226/819489db/attachment-0003.pl
More information about the Mono-devel-list
mailing list