ReturnEarlyException.TennisRunner 1.0.0

dotnet add package ReturnEarlyException.TennisRunner --version 1.0.0                
NuGet\Install-Package ReturnEarlyException.TennisRunner -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ReturnEarlyException.TennisRunner" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ReturnEarlyException.TennisRunner --version 1.0.0                
#r "nuget: ReturnEarlyException.TennisRunner, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ReturnEarlyException.TennisRunner as a Cake Addin
#addin nuget:?package=ReturnEarlyException.TennisRunner&version=1.0.0

// Install ReturnEarlyException.TennisRunner as a Cake Tool
#tool nuget:?package=ReturnEarlyException.TennisRunner&version=1.0.0                

ReturnEarlyException

A simple C# custom exception type for using return early style coding practices.

What is return early?

Return early means instead of wrapping your conditions in nested if/else braces.

You instead do a single condition check and then break out of that entire block if any of the conditions are untrue.

What are the advantages?

Return early style is less verbose since you no longer need to wrap everything in curly braces.

It also does not risk extending past the horizontal limit of your screen.

Lastly it is easier to read since it is a top down linear flow.

Examples

Return Early Style

while (true)
{
	try
	{
		int foo = 123;

		if (foo == 555)
			throw new ReturnEarlyException("Foo is 555. Not allowed");

		if (foo == 777)
			throw new ReturnEarlyException("Foo is 777. Not allowed");

		if (foo == 888)
			throw new ReturnEarlyException("Foo is 888. Not allowed");

		if (foo == 999)
			throw new ReturnEarlyException("Foo is 999. Not allowed");

		Console.WriteLine("Foo is valid");
	}
	catch (ReturnEarlyException e)
	{
		Console.WriteLine(e.Message);
	}

	Thread.Sleep(1000);
}

Nested Style

while (true)
{
	int foo = 123;

	if (foo != 555)
	{
		if (foo != 777)
		{
			if (foo != 888)
			{
				if (foo != 999)
				{
					Console.WriteLine("Foo is valid");
				}
				else
					Console.WriteLine("Foo is 999. Not allowed");
			}
			else
				Console.WriteLine("Foo is 888. Not allowed");
		}
		else
			Console.WriteLine("Foo is 777. Not allowed");
	}
	else
		Console.WriteLine("Foo is 555. Not allowed");
	
	Thread.Sleep(1000);
}
Product Compatible and additional computed target framework versions.
.NET Framework net35 is compatible.  net40 was computed.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 195 2/2/2023

Initial Release