maestrianet - Maestria.Extensions.FluentCast 2.2.0

Extension functions package for simple data convert.

PM> Install-Package Maestria.Extensions.FluentCast -Version 2.2.0 -Source https://www.myget.org/F/maestrianet/api/v3/index.json

Copy to clipboard

> nuget.exe install Maestria.Extensions.FluentCast -Version 2.2.0 -Source https://www.myget.org/F/maestrianet/api/v3/index.json

Copy to clipboard

> dotnet add package Maestria.Extensions.FluentCast --version 2.2.0 --source https://www.myget.org/F/maestrianet/api/v3/index.json

Copy to clipboard
<PackageReference Include="Maestria.Extensions.FluentCast" Version="2.2.0" />
Copy to clipboard
source https://www.myget.org/F/maestrianet/api/v3/index.json

nuget Maestria.Extensions.FluentCast  ~> 2.2.0
Copy to clipboard

> choco install Maestria.Extensions.FluentCast --version 2.2.0 --source https://www.myget.org/F/maestrianet/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "maestrianet" -SourceLocation "https://www.myget.org/F/maestrianet/api/v2"
Install-Module -Name "Maestria.Extensions.FluentCast" -RequiredVersion "2.2.0" -Repository "maestrianet" 
Copy to clipboard

Maestria.Extensions.FluentCast

NuGet Version NuGet Downloads Apimundo



buy-me-a-coffee smile.png

If my contributions helped you, please help me buy a coffee :D

donate


What is Maestria.Extensions.FluentCast?

This package provider a fluent syntax to simple data conversions. Extension functions package for simple data convert.

What is Maestria Project?

This library is part of Maestria Project.

Maestria is a project to provide maximum productivity and elegance to your code.

Where can I get it?

Install the Maestria.Extensions.FluentCast using the command line:

dotnet add package Maestria.Extensions.FluentCast

How do I get started?

First, import "Maestria.Extensions.FluentCast" reference:

using Maestria.Extensions.FluentCast;

Then in your application code, use fluent syntax:

// 1. Fixed point conversion
"150".ToInt32();      // string to int32 => 150
"150.345".ToInt32();  // string to int32, truncated => 150
150.345.ToInt32();    // double to int32, truncated => 150

// 2. Floating point conversion with culture
"150.45".ToFloat();                                        // uses default number culture
"150.45".ToDouble(CultureInfo.GetCultureInfo("en"));       // USA decimal separator "."
"150,45".ToDecimal(CultureInfo.GetCultureInfo("pt-BR"));   // Brazil decimal separator ","

// 3. Date and time conversion with culture
"2019-06-29 13:31:59".ToDateTime();                                     // uses default datetime culture
"6/29/19 1:31:59 PM".ToDateTime(CultureInfo.GetCultureInfo("en"));      // USA format "M/d/yyyy h:mm tt"
"29/06/2019 13:31:59".ToDateTime(CultureInfo.GetCultureInfo("pt-BR"));  // Brazil format "dd/MM/yyyy HH:mm"

// 4. Guid conversion
"a7fb69ba-7922-4d88-9569-d8d0d6641b86".ToGuid(); // string to Guid

// 5. String and byte array conversion
((object) null).ToStringSafe();      // null-safe ToString() => null
"hello".ToByteArray();               // string to byte[] using default encoding
"hello".ToByteArray(Encoding.UTF8);  // string to byte[] using a specific encoding

// 6. Boolean conversion
"true".ToBoolean();     // string to bool => true
1.ToBoolean();          // int to bool => true

// 7. Enum conversion
"Monday".ToEnum<DayOfWeek>();  // string to enum => DayOfWeek.Monday
1.ToEnum<DayOfWeek>();         // int to enum => DayOfWeek.Monday

// 8. Object cast
object obj = "hello";
obj.CastAs<string>();  // safe cast, "value as T" => "hello"
obj.CastTo<string>();  // unsafe cast, "(T) value" => "hello"

// 9. Safe conversion — returns a fallback instead of throwing
"broken input".ToInt32Safe();                   // output is a nullable int => null
"broken input".ToInt32Safe(-1);                 // output is an int => -1
"broken input".ToDateTimeSafe();                // output is a nullable DateTime => null
"broken input".ToDateTimeSafe(DateTime.Today);  // output is a DateTime => today

// 10. Validation — check convertibility without throwing
"150".IsValidInt32();           // true
"broken input".IsValidInt32();  // false
"Monday".IsValidEnum<DayOfWeek>(); // true

// 11. Unsafe conversion — throws on invalid input
"broken input".ToInt32();     // throws FormatException
"broken input".ToDecimal();   // throws FormatException
"broken input".ToDateTime();  // throws FormatException
"broken input".ToGuid();      // throws FormatException

Settings

It's possible set default culture format for library, when not configured, default culture is CultureInfo.InvariantCulture:

MaestriaFluentCastSettings.Configure(config => config
    .NumberCulture(<culture-info>) // Default is CultureInfo.InvariantCulture
    .DateTimeCulture(<culture-info>)); // Default is CultureInfo.InvariantCulture

See docs/usage/settings.md for full documentation.


Full usage documentations

There are many more extension methods available. See the full documentation:

Topic Sample methods
Numeric conversions ToInt16, ToInt32, ToInt64, ToFloat, ToDouble, ToDecimal, *Safe, IsValid*
Date & time conversions ToDateTime, ToTimeSpan, *Safe, IsValid*
Text & identifier conversions ToStringSafe, ToByteArray, ToGuid, ToGuidSafe, IsValidGuid
Boolean conversions ToBoolean, ToBooleanSafe, IsValidBoolean
Enum conversions ToEnum<T>, ToEnumSafe<T>, IsValidEnum<T>
Object cast CastAs<T>, CastTo<T>
Settings MaestriaFluentCastSettings.Configure

buy-me-a-coffee smile.png

If my contributions helped you, please help me buy a coffee :D

donate

  • .NETFramework 10.0
  • .NETFramework 5.0
  • .NETFramework 6.0
  • .NETFramework 8.0
  • .NETFramework 9.0
  • .NETStandard 2.0
  • .NETFramework 5.0: 5.0.0.0
  • .NETFramework 6.0: 6.0.0.0
  • .NETFramework 8.0: 8.0.0.0
  • .NETFramework 9.0: 9.0.0.0
  • .NETFramework 10.0: 10.0.0.0
  • .NETStandard 2.0: 2.0.0.0

Owners

Fábio Naspolini

Authors

Fábio Monteiro Naspolini

Project URL

https://github.com/MaestriaNet/Extensions.FluentCast

License

Unknown

Tags

Cast Data Conversion Convert Converter Simple Fluent Functional Elegance Productivity Maestria Mastery

Info

269 total downloads
13 downloads for version 2.2.0
Download (47.37 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
2.2.1 50.32 KB Tue, 21 Jul 2026 00:08:38 GMT 11
2.2.1-preview.pr-10 50.34 KB Tue, 21 Jul 2026 00:05:43 GMT 13
2.2.0 47.37 KB Mon, 20 Jul 2026 21:26:04 GMT 13
2.1.3-preview.pr-9 47.38 KB Mon, 20 Jul 2026 21:25:32 GMT 15
2.1.3-preview.pr-8 49.68 KB Mon, 20 Jul 2026 20:48:26 GMT 16
2.1.3-preview.pr-7 57.43 KB Mon, 20 Jul 2026 20:27:18 GMT 10
2.1.2 57.61 KB Wed, 01 Jul 2026 02:21:47 GMT 22
2.1.2-preview.pr-4 57.63 KB Wed, 01 Jul 2026 02:20:08 GMT 16
2.1.1 57.59 KB Tue, 30 Jun 2026 07:04:39 GMT 14
2.1.1-preview.pr-3 57.6 KB Tue, 30 Jun 2026 07:00:22 GMT 19
2.1.0 57.58 KB Thu, 25 Jun 2026 18:27:02 GMT 15
2.1.0-preview.1 57.59 KB Thu, 25 Jun 2026 18:23:58 GMT 18
2.0.0 19.36 KB Fri, 26 Aug 2022 15:21:57 GMT 87