Skip to content

Why do GuardClauses return a value and not the GuardClause or void? #244

Answered by amal-stack
Marvin-Brouwer asked this question in Q&A
Discussion options

You must be logged in to vote

The purpose of the return value is to simplify value assignment in constructors.

class Person
{
    public string Name { get; }
    public string Age { get; }
    public Person(string name, int age)
    {
        // return values used for assignment to Name and Age
         Name = Guard.Against.NullOrWhiteSpace(name); 
         Age = Guard.Against.NegativeOrZero(age);
    }
}

Without the return value, the constructor would be of four lines of code instead of two.
This has already been answered in #158.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Marvin-Brouwer
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants