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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:12:23+00:00 2026-05-11T03:12:23+00:00

Yesterday I was playing with jQGrid plugin and ASP.NET. Everything turned out well, my

  • 0

Yesterday I was playing with jQGrid plugin and ASP.NET. Everything turned out well, my grid is working now, but I have two methods, that make my code smell.

Smelly methods:

private IOrderedEnumerable<Employee> GetOrderedEmployees(Column sortColumn, bool ascending)     {         switch (sortColumn)         {             case Column.Name:                 {                     return GetOrderedEmployees(e => e.Name, ascending);                 }             case Column.Salary:                 {                     return GetOrderedEmployees(e => e.Salary, ascending);                 }             default:                 {                     return GetOrderedEmployees(e => e.ID, ascending);                 }         }     }      private IOrderedEnumerable<Employee> GetOrderedEmployees<TSortKey>(Func<Employee, TSortKey> func, bool ascending)     {         return ascending ? Context.Employees.OrderBy(func) : Context.Employees.OrderByDescending(func);     } 

I can’t find out, how to refactor them properly. It’s seems the best solution is to return only lambdas (f.e return e=>e.Name) in the switch statement, but how can it be done?

In the switch statement ascending argument is passed 3 times. Isn’t it a duplication?

  • 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-11T03:12:23+00:00Added an answer on May 11, 2026 at 3:12 am

    I think that you may be going over the top here. Returning lambdas (IMO) is far more confusing than a simple switch statement or if;else if;else block. There may be a better way, but sometimes you do need to check a condition, especially with columns (I HATE working with ListViews, but they are necessary and often require this kind of code.)

    I don’t think that you are at the point in which you need to refactor anything. If that switch statement becomes a maintenance headache, than go right ahead, but not all switch statements constitute ‘code smell’.

    To address your code duplication concern, you can use the switch to get the e.?? value first, save that off and then call the function once at the end of the method.

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

Sidebar

Related Questions

I asked a similar question yesterday, but now I have a slight twist. Since
Started playing around with jQuery and the jsTree plugin yesterday, and have it successfully
I just started playing about with emacs yesterday for a project I'm working on.
I'm new to MVC and I borrow a book from library yesterday on asp.net
I have been playing around with this problem since yesterday. I can't seem to
Yesterday everything works fine, but today I got many errors when I start my
Im developing my app and yesterday while I was playing with it crashed. I
I'm using C#.Net and have a base form that is inherited by several forms.
Now i know that this one is actually not a very technical question but
Yesterday, after about two years we re-deployed our application. Code hasn't changed, but the

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.