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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:43:33+00:00 2026-05-11T07:43:33+00:00

I have a class that is maps to a field in a database. The

  • 0

I have a class that is maps to a field in a database. The class only cares about the name of the field and its related .NET type. The type can be string, int, datetime, etc.

class Foo() {     string Name { get; set; }     Type FooType { get; set; } } 

I have another class that inherits from Foo that adds a property for a value. Right now I store the value as an object and use a switch statement to box the value based on the base classes FooType.

class FooWithStuff() : Foo {     object Value { get; set; }    } 

Is there way to implement this with generics to give type safety for the values?

Edit: I have made the key requirement bold. When declaring a list say Foo it needs a type. If I were doing this against custom classes I would create and interface and use that. However here I am using int, string, DateTime, etc. Int is a struct, string is an object, so a Foo< object> does not work for both.

  • 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. 2026-05-11T07:43:34+00:00Added an answer on May 11, 2026 at 7:43 am

    Define your class like this:

    class Foo<T> : IFoo {      public Foo(string name)     {         Name = name;     }      string Name { get; set; }     T Value {get; set;}     Type FooType { get { return typeof(T); } } } 

    You could then define the interface IFoo as:

    string Name { get; set; } Type FooType { get; set; } 

    And declare a list as:

    List<IFoo> list = new List<IFoo>(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that maps incoming messages to matching readers based on the
Anyone have a suggestion for a good utility class that maps values from one
I have a class that map objects to objects, but unlike dictionary it maps
I have class method that returns a list of employees that I can iterate
I have a POCO class called Attachment that maps to a table in SqlServer
I have a mapping that looks like this: <class name=Record> <map name=Values> <key column=RecordFK/>
So I have a class with three fields that maps to a table using
I have a data access class that loads reference data. Each type of entity
This is quite odd, because I have a Character class that can access Frame.dimension.getWidth();
I have this function that maps a IDataReader to a class. It is obviously

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.