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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:07:32+00:00 2026-05-25T15:07:32+00:00

I have written a simple extension method for HtmlHelper class like public static string

  • 0

I have written a simple extension method for HtmlHelper class like

public static string GetExpressionNames<TModel>(this HtmlHelper<TModel> helper,params Expression<Func<TModel,object>>[] args) where TModel:class
        {
            string returnStr = string.Empty;
            int i = 0;
            foreach (var x in args) 
            {
                returnStr += (++i).ToString() + ExpressionHelper.GetExpressionText(x) + "<br/>";
            }
            return returnStr;
        }

Currently, it’s just accepting array of LambdaExpressions defined on Model properties (returning object) and add their expression text to a string which is then returned by this function. The problem is that, for string type properties it’s working fine, but for int properties it’s returning the empty string as expression text. The reason is that for expression that returns int values the body of expression looks like following image:

enter image description here

but for strings, its like

enter image description here

I think convert method is expressions that return integar values is causing the empty string to be returned as Expression text. How can I get around this problem? I just need original expression text i.e Id for Convert(x.id) and Name for x.Name; it does not matter how it is processing it at the back end.

  • 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-25T15:07:33+00:00Added an answer on May 25, 2026 at 3:07 pm

    I have this extension method to do it for me

    public static string GetMemberName(this LambdaExpression expr) {
      var lexpr = expr;
      MemberExpression mexpr = null;
      if (lexpr.Body is MemberExpression) {
        mexpr = (MemberExpression) lexpr.Body;
      } else if (lexpr.Body is UnaryExpression) {
        mexpr = (MemberExpression) ((UnaryExpression) lexpr.Body).Operand;
      }
      if (mexpr == null) {
        return null;
      }
      return mexpr.Member.Name;
    }
    

    You may want to consider putting extra checks as if Convert doesn’t containt a memberexpression you will get a cast error.

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

Sidebar

Related Questions

I have written a very simple Chrome extension. It consists of this background page:
This is a simple script I have written to test command line argument handling:
I have written a secure TCP server in .NET. This was basically as simple
I've written a simple extension method for a web project, it sits in a
I have written a simple GUI in Python using the Tkinter library. This GUI
I've written this very simple function to replace a file extension using LINQ in
this is more theoretical question. I have written simple chat with my friend. We
I have written a simple PL SQL block , i am getting this error
I have written a simple brainfuck interpreter in MATLAB script language. It is fed
I have written a simple Java dispatcher with a daemon thread to handle 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.