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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:06:46+00:00 2026-06-09T18:06:46+00:00

I know that attributes are not supported inside the method body but i wanted

  • 0

I know that attributes are not supported inside the method body but i wanted to know maybe someone has work around this. What i am interested in is a technique that allows you to enter custom Attribute inside the method body and onto an two things.

  1. Class Intensiation (Creating Objects Foo foo = new Foo())
  2. When that object calls specific function (foo.bar())

later on I plan to use the metadata of the entered attributes using reflection. I came along a group of people that actually calims that they have extented c# to do so but because of no downloadable I am unable to verify it.

Here is the link to their research paper
Freely Annotating c#
Please advise me the solution

UPDATE

further with reflection I already know the name of class Foo and its method bar.
what the purpose of this is to know that foo called bar() in some method.

for Example

   static void Main()
       {
           [p1inst]  
           ConcretePrototype1 p1 = new ConcretePrototype1("I");

           [p1call]  
           ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
           Console.WriteLine("Cloned: {0}", c1.Id);

           // Wait for user 
           Console.Read();
       }

above is example that illustrate the outcome. At present it can not be done because compiler gives error. but the authors of above mentioned research paper have claimed that they have done this to allow attributes inside the method body

The whole point is to identify that in some method an object of type FOO exists and that object has called bar() or not

  • 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-06-09T18:06:47+00:00Added an answer on June 9, 2026 at 6:06 pm

    I think you are on the wrong track. You can’t have attributes inside a method. You either didn’t read the paper entirely or missed some points.

    It speaks of a source-to-source compiler that just translates

    public void m() {
        Console.WriteLine("Parallelable code sample");
        [Parallel("Begin of a parallel block")] {
            Console.WriteLine("Code exec by the main thread");
            [Process("First process")] { /∗ Computation here ∗/ }
            [Process] { /∗ Computation here ∗/ }
        }
        Console.WriteLine("Here is sequential");
    }
    

    into this C# code:

    [Parallel("Parallelable code sample", ACSIndex=1)]
    [Process("First process", ACSIndex=2)]
    [Process(ACSIndex=3)]
    public void m() {
        Console.WriteLine("Parallelable code sample");
        Annotation.Begin(1); { // [Parallel]
            Console.WriteLine("Code exec by the main thread");
            Annotation.Begin(2); /∗ [Process("First process")] ∗/ { · · · }
            Annotation.End(2);
            Annotation.Begin(3); /∗ [Process] ∗/ { · · · }
            Annotation.End(3);
        } 
        Annotation.End(1);
    }
    

    So when the method Begin(1) is called on the Annotation class, it will just lookup the method attribute with ASCIndex=1.


    To solve your actual problem, you should look into the StackTrace class.

    Example:

    void Main()
    {
        var f = new FooClass();
        f.Foo();
    }
    
    class BarClass
    {
        public static void Bar()
        {
            var st = new StackTrace();
            var frame = st.GetFrame(1);
            var m = frame.GetMethod();
            Console.WriteLine(String.Format("'{0}' called me from '{1}'", m.DeclaringType.Name, m));
        }
    }
    
    class FooClass
    {
        public void Foo()
        {
            BarClass.Bar();
        }
    }
    

    Output:

    ‘FooClass’ called me from ‘Void Foo()’

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

Sidebar

Related Questions

I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
I know that to filter an element with an atttribute called attrName which has
I know that Java have its own garbage collection, but sometimes I want to
I know that HTML5 supports custom data-* attributes , and I know that VS2010
I know that until recently it was not possible to select any specific compiler
The FOR command in Windows has some options that it did not have in
I of course know that I can rename the init arg for an attribute
I know normally that assigning a name attribute to the radio inputs would only
I know that if port 443 is open that means the remote host supports

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.