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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:56:35+00:00 2026-05-29T19:56:35+00:00

Apologies if this question has been asked before, I couldn’t find anything similar. I

  • 0

Apologies if this question has been asked before, I couldn’t find anything similar.

I have an enumerable choice that comes into my class:

public enum OrdinalValue
{
   None = 0,
   Qualification = 1,
   Career = 2,
   Faculty = 3
}

Based on this enumerable do I have 3 property calls that brings back data from an entity collection for each of these:

public List<Qualification> ByQualification { get; set; }
public List<Career> ByCareer { get; set; }
public List<Faculty> ByFaculty { get; set; }

I want to create a generic method that returns the correct property, based on the enum passed back from the calling method, something like:

public List<T> GetEntities<T>(OrdinalValue ord)
{
    List<T> value = default(List<T>);

    // based on enum, cast the correct List<T> and return value
    // something like:
    if (ord == OrdinalValue.Career)
        return (List<T>)Convert.ChangeType(this.ByCareer, typeof(T));

    return value;
}

Is it possible?

  • 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-29T19:56:38+00:00Added an answer on May 29, 2026 at 7:56 pm

    It sounds like you want something like:

    public List<T> GetEntities<T>(OrdinalValue ord)
    {
        object ret;
    
        switch(ord)
        {
            case OrdinalValue.Career:
                ret = ByCareer;
                break;
            case OrdinalValue.Faculty:
                ret = ByFaculty;
                break;
            case OrdinalValue.Qualification:
                ret = ByQualification;
                break;
            default:
                throw new ArgumentOutOfRangeException("ord");
        }
        return (List<T>) ret;
    }
    

    However, this doesn’t feel like a good design to me. It’s hard to suggest anything better without knowing more about the bigger picture, but it doesn’t really feel like a truly generic method.

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

Sidebar

Related Questions

First off, apologies if this question has been asked before but I couldn't find
My sincere apologies if this question has been asked, but I really couldn't find
Apologies if this question has been asked. I couldn't find it, but if it
First off - apologies if this or a similar question has been asked before.
My apologies if this question has been asked before. I can see there are
Apologies if this is too ignorant a question or has been asked before. A
I'm sure this question has been asked before, my apologies for not finding it
I hope this question (or one similar) hasn't been asked before. Sincere apologies if
Apologies if this has been asked before but it seems an obvious question for
Apologies if this question has been asked already, but suppose we have this code

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.