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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:39:24+00:00 2026-05-16T01:39:24+00:00

I have a class that implements an Interface with some methods. I also have

  • 0

I have a class that implements an Interface with some methods.
I also have method with an Action parameter where I pass the Interface method.
Is it possible to get the type of the owner that has the method?

EDIT
This is the wrapper:

private void Wrapper (params Action[] actions)
{
    var action = actions.FirstOrDefault();
    var type = action.Method.DeclaringType.Name;
}

private void test()
{
   Wrapper(()=> _GC.ChargeCancellation(""));
}

For demonstration purpose I don’t iterate through the collection.

I want the type of _GC.

  • 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-16T01:39:25+00:00Added an answer on May 16, 2026 at 1:39 am

    Actually, I should’ve spotted this to begin with but since Jon didn’t either I’m not feeling too bad about it 🙂

    The code you have to begin with in your question does not compile:

    Wrapper(() => TestClass.Hello);
    

    This is not complete code. You either have to have:

    Wrapper(TestClass.Hello);
            ^
            |
            +-- notice the missing () => here
    

    or:

    Wrapper(() => TestClass.Hello());
                                 ^
                                 |
                                 +-- notice the added parenthesis here
    

    And now that you have edited your question, it is clear you have the second form.

    There’s a subtle difference between the two. Subtle to us, but important to the compiler:

    Wrapper(TestClass.Hello);
            ^------+------^
                   |
                   +-- This is a method group
    
    Wrapper(() => TestClass.Hello());
                  ^------+--------^
                         |
                         +-- This is a method call
    

    A method group is a reference to a method (or its overloads), a method call is executable code.

    The difference to the compiler is that in the first piece of code, the compiler will wrap up the method group into an action, basically compile it like this:

    Wrapper(new Action(TestClass.Hello));
    

    and thus, you’re passing that method to the Wrapper method, inside an Action delegate.

    However, the second form is handled altogether differently. The compiler now produces a new method to contain your code, and then passes the new method to the Wrapper method instead of the code you had.

    Thus, your code actually looks like this:

    public static void Main()
    {
        Wrapper(new Action(TempMethod1));
    }
    
    private static void TempMethod1()
    {
        TestClass.Hello();
    }
    

    And that’s why you’re seeing the form class as the owner of the method, because that’s what it is.

    The reason I asked in a comment whether you were taking a delegate or an expression is that my brain was working at half speed. It detected something odd, but not the whole picture.

    If you want to pass code like this to a method, and work with it, you have two choices:

    1. For a delegate, work with reflection, decompile the code and analyze it, find the method call and figure out which class it is made on
    2. For an expression, analyze the pieces of the expression (this requires C# 3 or above)

    Since neither is trivial I’m not going to post any code here, suffice to say that what you’re asking warrants a new question. Of the two, I suggest you go with the expression way if you can.

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

Sidebar

Related Questions

I have a script that appends some rows to a table. One of the
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a new web app that is packaged as a WAR as part
Let say I have the following desire, to simplify the IConvertible's to allow me
My question is about memory use and objects in actionscript 2. If I have
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe
I have found this example on StackOverflow: var people = new List<Person> { new
I have a login.jsp page which contains a login form. Once logged in the
After having read Ian Boyd 's constructor series questions ( 1 , 2 ,

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.