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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:09:32+00:00 2026-05-16T09:09:32+00:00

Let’s suppose I have such helper methods used by some object. private int MatchRegex(string

  • 0

Let’s suppose I have such “helper” methods used by some object.

    private int MatchRegex(string regex, string input)
    {
        var match = Regex.Match(input, regex);
        return match.Success ? Convert.ToInt32(match.Groups[1].Value) : 0;
    }

    private string Exec(string arguments, string path = "", bool oneLine = false)
    {
        var p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.CreateNoWindow = true;

        if (path != "")
            p.StartInfo.WorkingDirectory = path;

        p.StartInfo.FileName = "binary.exe";
        p.StartInfo.Arguments = arguments;
        p.Start();

        string output = oneLine ? p.StandardOutput.ReadLine() : p.StandardOutput.ReadToEnd();
        p.WaitForExit();

        return output;
    }

Which would you choose to move out them: another class, partial class or extension methods? And why?

  • 1 1 Answer
  • 1 View
  • 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-16T09:09:33+00:00Added an answer on May 16, 2026 at 9:09 am

    If they accessed private state they would have to be methods in a partial class fragment. Extension methods are useful it it can support a range of objects, or the type can’t be used as a partial class (an interface being the most likely example, or outside of your assembly).

    Looking at those methods, they don’t really seem to relate to any given object, so I would do neither, and just expose them as static methods on a utility class. For example:

    public static class ProcessUtils {
        public static string Exec(...) {...}
    }
    

    The regex one is a different case; obtaining group 1 as an int seems such a specific scenario (unless there is something domain-specific in your project that makes this common-place), and the code is so trivial, that I would just let the calling code use the existing static Regex.Match. In particular, I would want the caller think about whether a static pre-compiled regex might be appropriate, which your utility method doesn’t allow.

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

Sidebar

Related Questions

Let's say I have the following classes : public class MyProductCode { private String
Let's say I have the string: hello world; some random text; foo; How could
Let's suppose I have this piece of code. foreach(string value in myList) { string
let's say we have some simple code like this : private static void Main()
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's suppose I have an XML file like this: <?xml version=1.0 encoding=ISO-8859-1?> <MIDIFile> <Event>
Let's suppose I have a Discussion model, and that a discussion can be tagged.
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>

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.