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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:58:39+00:00 2026-05-23T20:58:39+00:00

I have a .NET application which has a custom configuration to re-construct some classes

  • 0

I have a .NET application which has a custom configuration to re-construct some classes on startup. That’s not a plain (de)serialization, that’s more complex and mixed.

class FooElement : ConfigurationElement
{
     static ConfigurationProperty propValue = new ConfigurationProperty("value", typeof(int));
     static ConfigurationProperty propType = new ConfigurationProperty("type", typeof(string));

     [ConfigurationProperty("value")]
     public int Value
     {
         get { return (int)this[propValue] }
         set { this[propValue] = value }
     }

     [ConfigurationProperty("type")]
     public string Type
     {
         get { return (int)this[propType] }
         set { this[propType] = value }
     }
}

class Foo : IFoo
{
    public int Value { get; set; 
    public string Type { get; set; }
}

Some of configuration elements repeats application objects by properties, but I don’t want to use elements in my application, I created light-weight objects for this purpose. Probably I can call them POCOs.

Currently I have next: Config:

<elements>
    <add type="MyProj.Foo, MyProj" value="10" />
</elements>

Code:

elements.Select(e => (IFoo)Activator.CreateInstance(e.Type, e));

public Foo(FooElement element)
{
    this.Value = element.Value;
}

How to better to do that? Maybe using IoC or something similar.

  • 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-23T20:58:39+00:00Added an answer on May 23, 2026 at 8:58 pm
    interface IConfigurationConverter<TElement, TObject>
    {
        TObject Convert(TElement element);
    }
    
    class FooConfigurationConverter : IConfigurationConverter<FooElement, Foo>
    {
        public Foo Convert(FooElement element)
        {
            return new Foo { Value = element.Value };
        }
    }
    
    FooConfigurationConverter converter = IoC.Resolve<IConfigurationConverter<FooElement, Foo>>();
    Foo foo = converter.Convert(element);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp.net web application which has a number of versions deployed on
I have a ASP.NET web application which has more than 100 pages. Each page
HI All, We have a .Net 2.0 application which has a MySQL backend. We
I have a console application which has target .NET 2.0 It is very short
I have an ASP.NET MVC 2 application in which I am creating a custom
I have an ASP.NET MVC web application that implements a custom membership provider. The
I have a Windows application in .Net 2.0 that uses several levels of configuration
I have an ASP.NET application which tracks statistics by creating and writing to custom
I have a .NET application which serializes an object in binary format. this object
I have an .Net MVC application which runs fine if I use the build

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.