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

  • Home
  • SEARCH
  • 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 6345799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:53:35+00:00 2026-05-24T20:53:35+00:00

This is simplified setup – I have API (I have n o control on

  • 0

This is simplified setup – I have API (I have n o control on the API), which exposes a Func property like this:

public Func<dynamic, MyClass> FuncProperty { get; set; }

Usually it’s used like this:

api.FuncProperty = s =>
   {
      do1();
      do2();
      return new MyClass(); //simplified
   }

Similar code is used all over the place (of course the content in {} is different), and I want to add common functionality to all these, I’d like to create a “wrapper” method, which I can use like this:

api.FuncProperty = MyWrapperMethod( 
   s =>
   {
      do1();
      do2();
      return new MyClass();
   });

I know I can edit all these calls to look like:

api.FuncProperty = s =>
  {
     DoMyCommonFunctionality();
     //... as before
  }

But if my common functionality is something like:

using(var disposable = SetSomeState())
{
   //the stuff which previously was in the lambda
}

then, using the latter approach is kind of ugly.

That’s why even if it’s only for learning purposes, how should my wrapper’s method signature look like? And how should I use it?

  • 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-24T20:53:36+00:00Added an answer on May 24, 2026 at 8:53 pm

    If I understand you right, it should also return a Func<dynamic, MyClass>, like this:

    public static Func<dynamic, MyClass> MyWrapperMethod(Func<dynamic, MyClass> func)
    {
        // Validation if you want
        return d =>
        {
            using(var disposable = SetSomeState())
            {
                return func(d);
            }
        };
    }
    

    That’s an example with the using statment you wanted.

    Note that calling MyWrapperMethod does not call the delegate you pass into it. Instead, it returns a delegate which, when called, will call the delegate you passed. This sort of deferred execution can be confusing, but I believe it’s what you want here.

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

Sidebar

Related Questions

So I have a database that is setup sort of like this (simplified, and
I have a table setup like this (simplified for example): user_id item_id click_dt Each
I have code like this (simplified): def outer(): ctr = 0 def inner(): ctr
I have a table like this (simplified): ID | Name | Parent --------------------------------- 1
I have a virtual host setup on Apache 2 like so (simplified): <VirtualHost *>
I'm starting out with some XML that looks like this (simplified): <?xml version=1.0 encoding=UTF-8?>
I've got 3 tables that are something like this (simplified here ofc): users user_id
I've got a table of student information in MySQL that looks like this (simplified):
I have a multi-table query, similar to this (simplified version) SELECT columns, count(table2.rev_id) As
I have a MySql db with innoDB tables. Very simplified this is how two

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.