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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:28:22+00:00 2026-05-18T22:28:22+00:00

Imagine I have a set of global methods that aren’t associated with any specific

  • 0

Imagine I have a set of global methods that aren’t associated with any specific classes. Each method takes exactly one object and returns exactly one object of various types.

I want to be able to link these methods together so that the object returned by one method gets passed as a parameter to the next method and so on.
Extension methods are the easiest and most elegant way I can think of for accomplishing this:

var result = someObj.ExtensionMethod1().ExtensionMethod2().ExtensionMethod3();

However, I also have a log method which takes an object parameter and I want to pass the result of each method to this log method. For example:

var result1 = someObj.ExtensionMethod1();
log(result1);
var result2 = result1.ExtensionMethod2();
log(result2);
var result3 = result2.ExtensionMethod3();
log(result3);

Is there a more elegant of way of doing this so I won’t have to create temporary variables to pass every time I call a method?

  • 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-18T22:28:22+00:00Added an answer on May 18, 2026 at 10:28 pm

    You’re looking for

    public static T Log<T>(this T thing) {
        ...
        return thing;
    }
    
    var result = someObj.ExtensionMethod1().Log()
                        .ExtensionMethod2().Log()
                        .ExtensionMethod3().Log();
    

    (The generic parameter is needed so that the return value can be used without casting)

    LINQPad’s Dump() method works the same way.

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

Sidebar

Related Questions

We have a set of about two dozen classes that inherit from a base
Imagine that you have a large set of #m objects with properties A and
Imagine we have a set of entities each of which has its state: free,
I have a global event created and set/reset in a native C++ process that
Imagine I have some XML that looks like this: DECLARE @xml XML SET @xml
Imagine you have class A which has code which runs as method M. And
Imagine I have a cell that I want to be red if the value
Imagine you have an entity that has some relations with other entities and you
Imagine you have an std::list with a set of values in it. For demonstration's
I have created a script that analyzes a set of raw data and converts

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.