Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:02:49+00:00 2026-06-09T00:02:49+00:00

Based on my app.config I would like to be able to get the elements

  • 0

Based on my app.config I would like to be able to get the elements of columns as shown in the example below in lines 3-5. How should I write the code in order to achieve this. If I’ll need to change my app.config – I’ll do it.

1. var bounceProviders = ConfigurationManager.GetSection("BounceProviders") as BounceProvidersSection;
2. var providerColumns = bounceProviders.Providers[0].Columns;
3. var emailColumn = providerColumns.Email;
4. var dateColumn = providerColumns.Date;
5. var messageColumn = providerColumns.Message;

app.config

<BounceProviders>
  <Providers>
    <Provider Name="p1">        
      <Columns>
          <Email Name="My Email" />
          <Date Name="My Date" />
          <Message Name="My Message" />               
      </Columns>
    </Provider>  
    <Provider Name="p2">
      <Columns />
    </Provider>    
  </Providers>
</BounceProviders>

ConfigurationSection

public class BounceProvidersSection : ConfigurationSection
{
    [ConfigurationCollection(typeof(ConfigCollection<BounceProviderConfig>), AddItemName = "Provider")]
    [ConfigurationProperty("Providers", IsRequired = true)]
    public ConfigCollection<BounceProviderConfig> Providers
    {
        get { return (ConfigCollection<BounceProviderConfig>)this["Providers"]; }
        set { this["Providers"] = value; }
    }                
}

public class BounceProviderConfig : ConfigurationElement
{
    [ConfigurationProperty("Name", IsRequired = true)]
    public string Name
    {
        get { return (string)this["Name"]; }
        set { this["Name"] = value; }
    }            
}

ConfigCollection

public class ConfigCollection<T> : ConfigurationElementCollection
        where T : ConfigurationElement, new()
{        
    protected override ConfigurationElement CreateNewElement()
    {
        return new T();
    }

    protected override object GetElementKey( ConfigurationElement element )
    {
        return element.GetHashCode();
    }

    public T this[int index]
    {
        get
        {
            return ( T )BaseGet( index );
        }
        set
        {
            if ( BaseGet( index ) != null )
            {
                BaseRemoveAt( index );
            }
            BaseAdd( index, value );
        }
    }

    new public T this[string Name]
    {
        get
        {
            return ( T )BaseGet( Name );
        }
    }
}

sdf

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:02:52+00:00Added an answer on June 9, 2026 at 12:02 am

    I figured it out

    public class BounceProvidersSection : ConfigurationSection
    {
        [ConfigurationCollection(typeof(ConfigCollection<BounceProviderConfig>), AddItemName = "Provider")]
        [ConfigurationProperty("Providers", IsRequired = true)]
        public ConfigCollection<BounceProviderConfig> Providers
        {
            get { return (ConfigCollection<BounceProviderConfig>)this["Providers"]; }
            set { this["Providers"] = value; }
        }                
    }
    
    public class BounceProviderConfig : ConfigurationElement
    {
        [ConfigurationProperty("Id", IsRequired = true)]
        public int Id
        {
            get { return (int)this["Id"]; }
            set { this["Id"] = value; }
        }
    
        [ConfigurationProperty("Columns", IsRequired = false)]
        public BounceProviderColumns Columns
        {
            get { return (BounceProviderColumns)this["Columns"]; }
            set { this["Columns"] = value; }
        }
    
        public static BounceProviderConfig GetByProviderId(int providerId)
        {
            var section = ConfigUtils.GetConfigurationSection<BounceProvidersSection>("BounceProviders");
            foreach (BounceProviderConfig provider in section.Providers)
            {
                if (provider.Id == providerId)
                    return provider;
            }
    
            return null;
        }
    }
    
    public class BounceProviderColumns : ConfigurationElement
    {
        [ConfigurationProperty("Email", IsRequired = true)]
        public ColumnConfig Email
        {
            get { return (ColumnConfig)this["Email"]; }
            set { this["Email"] = value; }
        }
    
        [ConfigurationProperty("Date", IsRequired = true)]
        public DateColumnConfig Date
        {
            get { return (DateColumnConfig)this["Date"]; }
            set { this["Date"] = value; }
        }
    
        [ConfigurationProperty("Message", IsRequired = true)]
        public ColumnConfig Message
        {
            get { return (ColumnConfig)this["Message"]; }
            set { this["Message"] = value; }
        }        
    }
    
    public class ColumnConfig : ConfigurationElement
    {
        [ConfigurationProperty("Name", IsRequired = true)]
        public string Name
        {
            get { return (string)this["Name"]; }
            set { this["Name"] = value; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to store log4net config data in my application.config file. Based on
I have a UIDocument based app, without iCloud support. The user is able to
I would like to deploy multiple independent copies of a particular web-app on the
I would like to have my Sinatra app include a view specific stylesheet in
While I develop, I would like to see sinatra app exceptions when running tests,
Am doing a location based app.When using GPS, it provides with street names from
I have a subscription based app, charged on the basis of number of users
We have client server based app which saves user related data into a zip
I have a dialog-based app with an edit-control in it. When I minimize /
I have an ARC based app which loads about 2,000 fairly large (1-4MB) Base64

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.