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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:09:26+00:00 2026-06-10T17:09:26+00:00

I have a method which contains a series of calls to a method which

  • 0

I have a method which contains a series of calls to a method which checks if string input is null or empty. If its empty, it sets the 2nd parameter to false;

public bool inputsContainData()
{
    bool validInputs = True;

    _helper.StringContainsData(_view.FilePath1, validInputs);
    _helper.StringContainsData(_view.FilePath2, validInputs);

    //...

    Return validInputs;
}

The StringContainsData() method is in a class which is DI’d into the presenter. The method doesnt return anything since the result variable is of reference type.

public void StringContainsData(string input, bool result)
{
    if( string.IsNullOrEmpty(input))
    {
        result = false;
    }
}

Im having some issues with this because i cant mock the StringContainsData() and have it return a specific result. The only solution i can think of is if i include a second If statement as follows:

    public bool StringContainsData(string input, bool result)
    {
        if( string.IsNullOrEmpty(input))
        {
            if(result != false)
            {
                return false;
            }
        }
        else
        {
            if(result == false)
            {
                return false;
            }
        }
        return true;
    }

Thus stopping me from having True,False,True => final result = true rather than false.

Is there a better way of doing this?

  • 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-06-10T17:09:27+00:00Added an answer on June 10, 2026 at 5:09 pm

    The simplest is to restructure to chain the calls.

    There is no need for another if, simply ANDing the previous answer with the new one will work.

    public bool StringContainsData(string aString, bool answerToDate) {
        return answerToDate && !string.IsNullOrWhiteSpace(aString);
    }
    
    public bool inputsContainData() {        
        bool validInputs = True;        
    
        validInputs = _helper.StringContainsData(_view.FilePath1, validInputs);        
        validInputs = _helper.StringContainsData(_view.FilePath2, validInputs);        
    
        return validInputs;        
    }        
    

    or if you want to have some fun

    public bool inputsContainData() {        
        var inputs = new []{ _view.FilePath1, _view.FilePath2};
        return inputs.Aggregate(true, (ret, inp) => ret && !string.IsNullOrWhiteSpace(inp));        
    }  
    

    Notes:

    The last version looks like complication for its own sake but if you are going to add more file paths to check extending the array is simpler/safer than cut/past on the assignment/call lines.

    In the function, check ret first using the short circuit (&&) means that we do not need to check the current input if we have already failed.

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

Sidebar

Related Questions

I have a form which contains a series of fields like: <input type=text name=User[123]
In Qt, I have a method which contains a mutex lock and unlock. The
I have an abstract class which contains method for setting header text. It looks
I have my main application delegate which contains a method that returns an object.
I have a method which returns single word as a String. I need to
I have a TreeSet which contains > 100k objects. I have another method which
I have a method which contains a file upload control. It uses the .saveas
I have a method which contains a try-catch block and I don't know how
I have this page (code below) which contains a series of 5 checkboxes, all
I have a series of nested TableLayoutPanel controls which each of them contains lots

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.