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 6335763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:55:11+00:00 2026-05-24T18:55:11+00:00

How can I get and use an attribute set in the parent ConfigurationSection in

  • 0

How can I get and use an attribute set in the parent ConfigurationSection in the descendent CustomSetting element? I need this attribute when the CustomSetting element is returning the Value property.

I want to format the App.config like this:

<CustomSettings someProperty="foo">
    <CustomSetting key="bar" value="fermeneba" />
    <CustomSetting key="laa" value="jubaduba" />
</CustomSettings>

I have the code working, except that I cannot find a way to access the someProperty attribute from the CustomSetting class. The only way that I’ve found, so far, is to format the configuration like this, which is messy:

<CustomSettings>
    <CustomSetting someProperty="foo" key="bar" value="fermeneba" />
    <CustomSetting someProperty="foo" key="laa" value="jubaduba" />
</CustomSettings>
  • 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-05-24T18:55:13+00:00Added an answer on May 24, 2026 at 6:55 pm

    Achieving this is more difficult than it should be since the System.Configuration API doesn’t allow you to navigate from a ConfigurationElement to its parent. Hence, if you want to access some information that on a parent element you need to create that relationship manually. I’ve put together a sample implementation that does that for the config snippet in your question:

    public class CustomSettingsSection : ConfigurationSection
    {
        [ConfigurationProperty("someProperty", DefaultValue="")]
        public string SomeProperty
        {
            get { return (string)base["someProperty"]; }
            set { base["someProperty"] = value; }
        }
    
        [ConfigurationProperty("", IsDefaultCollection = true)]
        public CustomSettingElementCollection Elements
        {
            get 
            {
                var elements = base[""] as CustomSettingElementCollection;
                if (elements != null && elements.Section == null)
                    elements.Section = this;
                return elements;
            }
        }
    }
    
    public class CustomSettingElementCollection : ConfigurationElementCollection
    {
    
        internal CustomSettingsSection Section { get; set; }
    
        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }
    
        public CustomSettingElement this[string key]
        {
            get { return BaseGet(key) as CustomSettingElement; }
        }
    
        protected override ConfigurationElement CreateNewElement()
        {
            return new CustomSettingElement { Parent = this };
        }
    
        protected override object GetElementKey(ConfigurationElement element)
        {
            return (element as CustomSettingElement).Key;
        }
    
        protected override string ElementName
        {
            get { return "customSetting"; }
        }
    }
    
    public class CustomSettingElement : ConfigurationElement
    {
    
        internal CustomSettingElementCollection Parent { get; set; }
    
        public string SomeProperty
        {
            get
            {
                if (Parent != null && Parent.Section != null)
                    return Parent.Section.SomeProperty;
                return default(string);
            }
        }
    
    
    
    
        [ConfigurationProperty("key", IsKey = true, IsRequired = true)]
        public string Key
        {
            get { return (string)base["key"]; }
            set { base["key"] = value; }
        }
    
        [ConfigurationProperty("value", DefaultValue = "")]
        public string Value
        {
            get { return (string)base["value"]; }
            set { base["value"] = value; }
        }
    
    }
    

    You can see that the CustomSettingElementCollection has a Section property which gets set in the section’s Elements getter. The CustomSettingElement, in turn, has a Parent property which gets set in the collection’s CreateNewElement() method.

    That then makes it possible to walk up the relationship tree and to add a SomeProperty property to the element even though this one doesn’t correspond to an actual ConfigurationProperty on that element.

    Hope that gives you an idea how to solve your problem!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know i can get the attribute names, types, and set their values from
Does anyone know how I can get a format string to use bankers rounding
When I use the MouseUp event, I can get it to fire with a
I am wondering how I can get the document title in LaTex, for use
Can I get a 'when to use' for these and others? <% %> <%#
How can I get the javac task to use an existing fileset? In my
How can you get the directory of the script that was run and use
How can I get output from Java anonymous classes? In .Net I would use
How can I get the current selected row for UIPicker? I want to use
I can not get logs from some customers, can I use Google Urchin in

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.