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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:28:48+00:00 2026-05-21T05:28:48+00:00

I know there are ways, but is there actually a good way? At the

  • 0

I know there are ways, but is there actually a good way?

At the moment I have a decent Attribute based framework which is working really well with the exception of the verbosity of:

public Variable<int> Value { get { return Get.Int(MethodBase.CurrentMethod()); } }

Picture that, * a few hundred (with setters often too). Is there anyway to get the same result but more concise?

I’ve considered:

public Variable<int> Value { get { return Get.Int("Value"); } }

and tried:

public Variable<int> Value { get { return Get.Int(() => Value); } }

But as there’s many, many of these variables (there is method in this madness, I promise) I’m concerned about obscure bugs arising from the second Value (or string) not matching the first.

So my question is, can anyone think of a neater way to write the above? All I need is the current property name.

My favourite “solution” so far has been:

protected Func<MethodBase> Self = MethodBase.GetCurrentMethod;
public Variable<int> Value { get { return Get.Int(Self()); } }

Which is short, sweet, and pretty to look at.

But alas the JIT kills rules that out as an option. Is there perhaps a way I can rewrite GetCurrentMethod in C#, under a different name? It’s a pity StackCrawlMark (which I believe is required) is internal to System.

Alternatively, are there any tools out there that are compatible with ReSharper but perhaps let me view the code through goggles, reducing the verbose MethodBase.GetCurrentMethod to something shorter and sweeter, whilst still compiling exactly the same? (I’d really rather not have a pre-compile fiddling step, but am open to suggestions – one that reduced it all to the property name would be nice).

  • 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-21T05:28:49+00:00Added an answer on May 21, 2026 at 5:28 am

    In short, no. There are various attempts at this, including stack inspection (GetCurrentMethod) and lambda expressions, but ultimately they are all a bit inefficient.

    Unless you need need obfuscation, I would just use a string – Get.Int("Value") – this is very unlikely to be a genuine maintenance problem.

    The stack inspection approach suffers from potential brittleness if it inlines; if you need obfuscation, I would probably go with Expression. Or just mark the method as “don’t obfuscate this name”.

    Another approach would be to have an abstract base type, and use meta-programming to create the concrete type with the right data/code at runtime, based on inspecting your attributes.

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

Sidebar

Related Questions

I know that technically all three ways below are valid, but is there any
Disclaimer: I know there are better ways to track email open rates, which are
I know there are ways to get the number of digits after a decimal
I know there are two ways, [self.navigationController pushViewController:siteViewController animated:YES]; [self presentModalViewController:anotherViewController animated:YES]; However, those
I know there are three ways to change the view in iOS 1. [self
First off, I know there are many different easier/reliable ways to perform what I
I know that there are more practical ways of going about what I'm trying
I know a great thing about perl is that there's multiple ways of doing
I know there have been many questions on grid and pack in the past
Vim (actually, gvim is in question, but I believe it works both ways) upon

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.