ToolBX.EasyTypeParsing 2.2.0

dotnet add package ToolBX.EasyTypeParsing --version 2.2.0
NuGet\Install-Package ToolBX.EasyTypeParsing -Version 2.2.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="ToolBX.EasyTypeParsing" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToolBX.EasyTypeParsing --version 2.2.0
#r "nuget: ToolBX.EasyTypeParsing, 2.2.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 ToolBX.EasyTypeParsing as a Cake Addin
#addin nuget:?package=ToolBX.EasyTypeParsing&version=2.2.0

// Install ToolBX.EasyTypeParsing as a Cake Tool
#tool nuget:?package=ToolBX.EasyTypeParsing&version=2.2.0

autoinject

EasyTypeParsing

Extension methods to make it easier to parse strings into other types.

public void DoSomeShadyStuff(string aNumberMaybe, string definitelyANumber, string iDontCareIfItsANumber)
{
  //A number... maybe? Let's try to parse it into an integer without throwing exceptions
  var number = aNumberMaybe.ToInt();
  
  if (number.IsSuccess)
  {
    //It worked! This is a number!
  }
  else
  {
    //It wasn't a number after all :(
  }
  
  //If it's definitely a number then we don't have to use white gloves with this one! Convert it or throw in a very savage manner!
  var otherNumber = definitelyANumber.ToIntOrThrow();
  
  //This one could be garbage or a number... but I'm okay with getting a big fat zero in case it failed
  var meh = iDontCareIfItsANumber.ToIntOrDefault();
}

I can hear you say "It's all well and good but what if I want to parse Dates?!"

public void DoMoreShadyStuff(string disguisedDate)
{
  var myDate = disguisedDate.ToDateTimeOrThrow();
}

There are methods for most common primitive and not-so-primitive types.

//You can also do the following if you don't know the type ahead of time
public void IntensifyShadyness<T>(string ummWhatIsThis)
{
  var thingy = ummWhatIsThis.Parse<T>();
  
  var definiteThingy = ummWhatIsThis.ParseOrThrow<T>();
  
  var recklessThingy = ummWhatIsThis.ParseOrDefault<T>();
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ToolBX.EasyTypeParsing:

Package Downloads
ToolBX.Mathemancy

A bundle for generic geometry types such as Vector2<T>, Size<T> and Rectangle<T>

ToolBX.DML.NET

.NET implementation of the Dialog Markup Language.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 1,108 1/12/2024
2.2.0-beta1 321 11/24/2023
2.0.1 1,028 4/25/2023
2.0.0 499 11/9/2022
2.0.0-beta1 507 9/20/2022
1.0.1-beta1 127 9/20/2022
1.0.0 7,769 12/21/2021