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

  • Home
  • SEARCH
  • 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 8792173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:56:35+00:00 2026-06-13T22:56:35+00:00

I have a settings class, which has some properties for usability and to restrict

  • 0

I have a “settings” class, which has some properties for usability and to restrict set accessor. It seems easy while i had within ten items, but then their count was increased. I need some way to create these properties automatically, something like that:

foreach(var property in SettingsList)
{
    _settings.AddAutoProperty(property);
}

It may have deal with reflection, but i can’t get to efficient solution.

The properties definition:

public bool cbNextExcCount
{
    get { return (bool)this.GetValueById("cbNextExcCount"); }
}

public bool cbSaveOnChangeExc
{
    get { return (bool)this.GetValueById("cbSaveOnChangeExc"); }
}

public bool cbAutoIncrement
{
    get { return (bool)this.GetValueById("cbAutoIncrement"); }
}

public bool cbRememberOnExit
{
    get { return (bool)this.GetValueById("cbRememberOnExit"); }
}

...etc.

UPDATE
To summ up, i wrote the next code:

public IDictionary<string, object> Properties = new ExpandoObject();
private List<string> SettingsList = new List<string> 
{ 
    "cbNextExcCount",
    "cbSaveOnChangeExc",
    "cbAutoIncrement",
    "cbRememberOnExit"
};

public void CreateProperties()
{
    foreach (string SettingName in SettingsList)
    {
        Properties.Add(SettingName, () => this.GetValueById(SettingName));
    }
}

But i have an error on () => this.GetValueById("cbNextExcCount")):

argument type ‘lambda expression’ is not assignable to parameter type ‘object’.

I can store Func<bool>, but settings may have other type than bool and if i use Func, it’s get a bit more complicate to call.

  • 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-13T22:56:36+00:00Added an answer on June 13, 2026 at 10:56 pm

    You can’t create auto-properties, but you can use an ExpandoObject.

    I’m not sure if this is what you’re looking for, because using expandos means using duck typing (i.e. dynamic programming).

    ExpandoObject sample:

    dynamic expando = new ExpandoObject();
    expando.PropertyA = "Hello";
    expando.PropertyB = "world!";
    

    An interesting thing about expandos is that ExpandoObject implements IDictionary<string, object>, meaning that you can upcast any expando to this type and iterate over its added properties, which could be great for storing run-time created settings.

    UPDATE

    I was thinking more about a good solution and if SettingList is a custom class developed by yourself, maybe you can add a property called Custom to SettingList and add there settings that aren’t added during design-time.

    UPDATE 2

    In your case, instead of storing the actual value of something, you could add Func<bool> to ExpandoObject‘s run-time settings:

    IDictionary<string, object> settings = new ExpandoObject();
    settings.Add("cbNextExcCount", () => this.GetValueById("cbNextExcCount"));
    

    Actually, I don’t know this scope in your code sample, but change this to anything that could be an instance of SettingList or whatever.

    Once you’ve added run-time settings, you can type settings variable to dynamic typing in order to access properties like this:

    dynamic allSettings = (dynamic)settings;
    bool cbNextExcCount = allSettings.cbNextExcCount();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# class library A which has some configuration settings in its
I have a C#/.NET Winforms application which has some settings stored using A '.settings'
I have a class library that has settings within an app.config. I know that
I never used Settings class before but I found some articles on CodeProject which
I have an application which has a Prefernces Class and I want to know
Let's say I have a class Customer, which has a property customerType. I have
On my site I have a config file which has many settings that need
I have a base class which has a method for moving files to appropriate
I am creating a custom control which has some properties on it. The problem
I have an abstract class which contains method for setting header text. It looks

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.