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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:49:04+00:00 2026-05-26T12:49:04+00:00

In our code base public ActionResult Copy(string id, string targetId) { //lot of similar

  • 0

In our code base

public ActionResult Copy(string id, string targetId)
            {
                //lot of similar code
                Copy(sourcePageRef, destinationPageRef);
                //lot of similar code
            }

and

public ActionResult Move(string id, string targetId)
        {
            //lot of similar code
            Move(sourcePageRef, destinationPageRef);
            //lot of similar code
        }

the problem is, Copy and Move have different signatures:

PageRef Copy(PageRef, PageRef)

and

void Move(PageRef, PageRef)

How can I refactor these methods to avoid duplication?
Thank you

  • 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-26T12:49:05+00:00Added an answer on May 26, 2026 at 12:49 pm

    If you don’t need the result of Copy, you could still use an Action<string, string> or whatever the type is:

    public ActionResult Copy(string id, string targetId)
    {
        CopyOrMove((x, y) => Copy(x, y));
    }
    
    public ActionResult Move(string id, string targetId)
    {
        CopyOrMove(id, targetId, (x, y) => Move(x, y));
    }
    
    private void CopyOrMove(string id, string targetId,
                            Action<string, string> fileAction)
    {
        // lot of similar code
        fileAction(sourcePageRef, destinationPageRef);
        // lot of similar code
    }
    

    That’s one option. It depends on what the “lot of similar code” is really doing, and whether the second block needs the results of the first block. For example, if you could do this:

    public ActionResult Copy(string id, string targetId)
    {
        string sourcePageRef = PrepareSourceFile(id, targetId);
        string targetPageRef = PrepareTargetFile(targetId);
        Copy(sourcePageRef, targetPageRef);
        CleanUp(sourcePageRef, targetPageRef);
        return ...;
    }
    
    public ActionResult Move(string id, string targetId)
    {
        string sourcePageRef = PrepareSourceFile(id, targetId);
        string targetPageRef = PrepareTargetFile(targetId);
        Move(sourcePageRef, targetPageRef);
        CleanUp(sourcePageRef, targetPageRef);
        return ...;
    }
    

    … then that’s probably simpler than the refactoring-with-a-delegate approach.

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

Sidebar

Related Questions

We have recently started using FxCop on our code base and I am in
I have introduced boost to our code base, on my machine I created a
We have a medium sized ColdFusion code base for our Intranet and Website. For
Found the following code in our code base: public static final int DEFAULT_LENGTH =
I just saw some code in our code base (and it's OLD code, as
We are running Selenium regression tests against our existing code base, and certain screens
Me and several other developers are currently cleaning up our legacy code base, mostly
We're finally migrating our unit test code base from JUnit 3 to JUnit 4.
Our rails app is designed as a single code base linking to multiple client
I came across this code while working through code-analysis warnings on our code base.

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.