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

The Archive Base Latest Questions

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

I am building an application where the datamodel is fixed, but people (or just

  • 0

I am building an application where the datamodel is fixed, but people (or just me) can extend it by adding classes that inherit from the base class that gets instantiated from the info in the db and serialized in services.

I have three problem areas with this (case 1 2 and 3 in the sample code below).
Case #1 I could maybe solve with an interface, but that doesn’t help me with case 2 or 3.

I think the code sample will speak better than my attempts to explain; any idead on how to approach this so that each new field type doesn’t need to get manually added to a bunch of places in the code?

    public class ManagerClass
{
    public ManagerClass()
    {

        public ManagerClass()
        {
        }

        //Case #1
        public void process(AllFields allFields)
        {
            foreach (Field field in allFields.Fields)
            {
                //Currently I need to add all extention types as seperate cases here manually
                //...this type of logic appears in several places in the code
                if (field.GetType().Name == "ExtendedField")
                {
                    //Have the extended field do something in a way particular to it
                }
                else
                {
                    //Have the base field do something the "normal" way
                }
            }
        }
        //Case #2
        //Here is another case where currently I am adding each case in by hand
        //fieldType is a string here because I am storing what type of field it is in the DB
        public void create(string value, string fieldType)
        {
            //Currently I need to add all extention types as seperate cases here manually
            if (fieldType == "ExtendedField")
            {
                //Create a ExtendedField
            }
            else
            {
                //Create a Field
            }
        }
    }
}

[DataContract]
//Case #3
[KnownType(typeof(ExtendedField))] //Currently I need to add all extention types here manually
public class AllFields
{
    private List<Field> fields;
    public AllFields(){}

    [DataMember]
    public List<Field> Fields
    {
        get { return fields; }
        set { fields = value; }
    }
}

[DataContract]
public class Field
{
    private string fieldValue;
    public Field(){}

    [DataMember]
    public string FieldValue
    {
        get { return fieldValue; }
        set { fieldValue = value; }
    }
}

[DataContract]
public class ExtendedField : Field
{
    private string someOtherAttribute;
    public ExtendedField(){}

    [DataMember]
    public string SomeOtherAttribute
    {
        get { return someOtherAttribute; }
        set { someOtherAttribute = value; }
    }
}
  • 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:08:06+00:00Added an answer on May 23, 2026 at 8:08 pm

    Sounds like you’re trying to build an miniature extensibility framework. Consider something like this where the extension logic is handled by a FieldHandler:

    public class FieldHandler
    {
       public virtual Field CreateField(string value, string fieldType){...}
    }
    
    // Case 2
    Field field = null;
    foreach (FieldHandler handler in m_handlers)
    {
       if (handler.SupportsFieldType(fieldType))
       {
           field = handler.CreateField (value, fieldType);
           continue;
       }
    }
    if (field == null)
    {
       // Create standard field.
       field = ...;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used the step-by-step building application from the http://msdn.microsoft.com/en-us/library/hh202876(v=vs.92).aspx but the .sdf file won't
I'm building an application that gets movie information from themoviedb.com. The information is provided
I am building application that required some data from iPhone's Call log(read only). The
Background: We're building an application that allows our customers to supply data in a
I'm using this script for building application from command line: #!/bin/bash TARGET=signtest CONFIGURATION=Debug SDK=iphoneos
Building an application with a database that has the ability to get big not
Im building an application that requires extensive logging of actions of the users, payments,
I'm building an application against a legacy database that stores lookup values in a
I am building a application I need to animate logo just like skype application.
After update Android SDK revision 21 for building application with Android 4.2. But now,

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.