Marco Canini wrote:
I attach here a modified versrion of ProviderSectionHandler that solves some pbs i had while trying to use mono.data.providerfactory.
A more detailed comment is included in the file header.
I don't send a patch because last time Miguel wasn't able to apply.
I modified ProviderSectionHandler.cs shipped with mcs 0.28
Please commit it to CVS and let Mono.Data.dll be built by default in make all.
If you've questions i'm here.
_______________________________________________ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list
// // Mono.Data.ProviderSectionHandler // // Authors: // Brian Ritchie ([EMAIL PROTECTED]) // // // Copyright (C) Brian Ritchie, 2002 // // Modified by Marco Canini <[EMAIL PROTECTED]> on 24 October 2003 // * Use XPath to select all provider node under providers to get sure it doesn't // throw exception when there're comments and whitespaces in providers node
using System;
using System.Xml;
using System.Configuration;
namespace Mono.Data
{
public class ProviderSectionHandler : IConfigurationSectionHandler
{
public virtual object Create(object parent,object
configContext,XmlNode section)
{
ProviderCollection providers = new ProviderCollection ();
XmlNodeList ProviderList = section.SelectNodes ("./provider");
foreach (XmlNode ProviderNode in ProviderList) {
Provider provider = new Provider (
GetStringValue (ProviderNode,"name",true),
GetStringValue
(ProviderNode,"connection",true),
GetStringValue (ProviderNode,"adapter",true),
GetStringValue (ProviderNode,"command",true),
GetStringValue (ProviderNode,"assembly",true),
GetStringValue
(ProviderNode,"description",false));
providers.Add (provider);
}
return providers;
}
private string GetStringValue(XmlNode _node, string _attribute, bool
required)
{
XmlNode a = _node.Attributes.RemoveNamedItem (_attribute);
if (a == null) {
if (required)
throw new ConfigurationException ("Attribute
required: " + _attribute);
else
return null;
}
return a.Value;
}
}
}
