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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:32:54+00:00 2026-05-23T22:32:54+00:00

GetCached(BLCustomer.GetAll, GetAll); where GetAll is session key. How can I do something like this?

  • 0
GetCached(BLCustomer.GetAll, "GetAll");

where "GetAll" is session key.
How can I do something like this?

GetCached(BLCustomer.GetAll, BLCustomer.GetAll.ToString());

UPDATE:

other worlds I wanna to get the string "GetAll" (not names of customers, but the name of the method) from method name BLCustomer.GetAll().

I want to use something like this

GetCached(BLCustomer.GetSingle, BLCustomer.GetSingle.ToString());

instead of

GetCached(BLCustomer.GetSingle, "GetSingle");

to avoid hardcoding name of methods.

  • 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-23T22:32:54+00:00Added an answer on May 23, 2026 at 10:32 pm

    SIMPLE SOLUTION: (stolen from leppie below)

    Simply remove the second parameter from your GetCached method:

    ReturnType GetCached(Func<T> func)
    {
        var name = func.Method.Name;
    
        // execute func here
    }
    

    This assumes, that it will be called like this:

    GetCached(BLCustomer.GetAll);
    

    and not like this:

    GetCached(() => BLCustomer.GetAll());
    

    COMPLEX SOLUTION:

    You can do it like this:

    string GetMethodName(Expression<Func<Func<dynamic>>> methodExpression)
    {
        dynamic memberExpression = methodExpression.Body;
        MethodInfo result = memberExpression.Operand.Arguments[2].Value;
        return result.Name;
    }
    

    Call it like this:

    GetCached(BLCustomer.GetSingle, GetMethodName(() => BLCustomer.GetSingle));
    

    This approach makes two assumptions:

    1. The call always needs to look like in the example, i.e. it mustn’t have a parameter and the body of the delegate must contain only the method you want the name from and nothing else
    2. The method you want the name from must not be of type void and must not have any parameters.

    You can use this also for non static methods:

    BLCustomer customer = new BLCustomer();
    GetCached(customer.GetSingle, GetMethodName(() => customer.GetSingle));
    

    You can even change GetCached to the following to cleanup its API:

    ReturnType GetCached<T>(Expression<Func<Func<T>>> methodExpression)
    {
        var name = GetMethodName(methodExpression);
        var func = methodExpression.Compile()();
    
        // execute func and do stuff
    }
    

    For this to work, you need to make GetMethodName generic instead of using dynamic:

    string GetMethodName<T>(Expression<Func<Func<T>>> methodExpression)
    {
        dynamic memberExpression = methodExpression.Body;
        MethodInfo result = memberExpression.Operand.Arguments[2].Value;
        return result.Name;
    }
    

    And then you can call it like this:

    GetCached<IEnumerable<Customer>>(() => BLCustomer.GetAll)
    GetCached<Customer>(() => BLCustomer.GetSingle)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v4.0. Update: I've hacked together this so far: public class AllFilter :
As you may know Coherence provides filtering api against its cache-cluster, like this: //
Let's say I start with a single CacheManager like this: private static CacheManager manager
I am trying to do a simple thing like store something in the cache
This is the XMLHttpRequest: $.ajax({ method: get, url: getPage.php, data: $data, dataType: 'json', timeout:
I have read somewhere that javascript and css files that only get cached in
I understand the need for a function like DB_Get_Cached(sql string) that hashes the SQL
First of all, I'd like to say I'm not using any off-line feature from
Whenever I install a new font on a Windows 2003 server, I can't use
I have this configuration for ehCache: <ehcache> <defaultCache name=defaut maxElementsInMemory=5 eternal=false timeToIdleSeconds=20 timeToLiveSeconds=20 overflowToDisk=false

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.