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

The Archive Base Latest Questions

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

So I got this crazy idea I could make make something cool work. I

  • 0

So I got this crazy idea I could make make something cool work. I got tired of new selectlist(item, “blah”, “blahblah”) so I started writing an extension method (trying to get it more strongly typed) something like this …

var selectList = projects.ToSelectList(p =>p.ProjectID, p =>p.ProjectName);

the extension method goes a little like this

public static SelectList ToSelectList<T>(this IEnumerable<T> item, 
                           Expression<Func<T, string>> textName, 
                           Expression<Func<T, string>> valueProperty)
    {
        //do cool stuff
        return new SelectList(items, dataTextField, dataValueField);
    }

What I need to get to is the reflection properties so I can grab the value and grab the name. Any ideas onhow I can do that? Any thoughts on doing this more better/easier? I’ve done this before but for the life of me I can’t remember how I did it.

Edit this needed some clarification. I copied some code that was in-flight and not refined, so I’ve updated that code to reflect the more correct criteria.

  • 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-16T07:33:18+00:00Added an answer on May 16, 2026 at 7:33 am

    I don’t see why you have to use Reflection to do this.

    public static SelectList ToSelectListItem<T>(this IEnumerable<T> items, 
        Func<T, string> textName, Func<T, string> valueProperty) {
        {
        return new SelectList(items
                .Select(i => new SelectListItem {Text = textName(i), Value = valueProperty(i)}));
        }
    }
    

    should would work, but I don’t have the MVC dll on the current machine.

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

Sidebar

Related Questions

I got this crazy idea that I don't know is possible or not... what
I got this very weird code: No debug, no work! I am almost crazy
I am newbie of objective-c and i got this crazy problem… for low precision
This is driving me crazy and must be simple. Basically, I've got a little
This has got to be simple -- surely this method is supposed to work
So this is driving me crazy. I've got an advanced data grid with a
I've got this crazy javascript issue with IE7 and IE8. The function expression below
I got this crazy problem I'm trying to deal with. I know that when
I've got this simple problem that is really making me crazy. I've got a
Im a little new to JS and this has got me scratching my head

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.