Example #1
0
        private object EvaluateRecursive(IConfigurationSectionHandler factory, object config, string[] keys, int iKey, XmlTextReader reader, object context)
        {
            string name  = keys[iKey];
            int    depth = reader.Depth;

            while (reader.Read() && reader.NodeType != XmlNodeType.Element)
            {
                ;
            }

            while (reader.Depth == depth + 1)
            {
                if (reader.Name == name)
                {
                    if (iKey < keys.Length - 1)
                    {
                        config = EvaluateRecursive(factory, config, keys, iKey + 1, reader, context);
                    }
                    else
                    {
                        // Call configuration section handler
                        int line = reader.LineNumber;

                        // Try-catch is necessary to protect from exceptions in user config handlers
                        try
                        {
                            ConfigXmlDocument doc = new ConfigXmlDocument();
                            doc.LoadSingleElement(filename, reader);
                            config = factory.Create(config, context, doc.DocumentElement);
                        }
                        catch (ConfigurationException)
                        {
                            // Bubble ConfigurationExceptions
                            throw;
                        }
                        catch (XmlException)
                        {
                            // Bubble XmlExceptions
                            throw;
                        }
                        catch (Exception ex)
                        {
                            // Wrap all others as ConfigurationExceptions
                            throw new ConfigurationException("Exception in ConfigSectionHandler", ex, filename, line);
                        }
                    }
                    continue;
                }
                StrictSkipToNextElement(reader);
            }
            return(config);
        }
		private object EvaluateRecursive(IConfigurationSectionHandler factory, object config, string[] keys, int iKey, XmlTextReader reader)
		{
			string name = keys[iKey];
			int depth = reader.Depth;
			
			while(reader.Read() && reader.NodeType != XmlNodeType.Element);

			while (reader.Depth == depth + 1)
			{
				if (reader.Name == name)
				{
					if (iKey < keys.Length - 1)
					{
						config = EvaluateRecursive(factory, config, keys, iKey + 1, reader);
					}
					else 
					{
						// Call configuration section handler
						int line = reader.LineNumber;

						// Try-catch is necessary to protect from exceptions in user config handlers
						try
						{
							ConfigXmlDocument doc = new ConfigXmlDocument();
							doc.LoadSingleElement(filename, reader);
							config = factory.Create(config, null, doc.DocumentElement);
						}
						catch(ConfigurationException)
						{
							// Bubble ConfigurationExceptions
							throw;
						}
						catch (XmlException)
						{
							// Bubble XmlExceptions
							throw;
						}
						catch(Exception ex)
						{
							// Wrap all others as ConfigurationExceptions
							throw new ConfigurationException("Exception in ConfigSectionHandler", ex, filename, line);
						}
					}
					continue;
				}
				StrictSkipToNextElement(reader);
			}
			return config;
		}