FluentCoding.String 1.0.3

There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package FluentCoding.String --version 1.0.3
                    
NuGet\Install-Package FluentCoding.String -Version 1.0.3
                    
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="FluentCoding.String" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluentCoding.String" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="FluentCoding.String" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FluentCoding.String --version 1.0.3
                    
#r "nuget: FluentCoding.String, 1.0.3"
                    
#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.
#:package FluentCoding.String@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FluentCoding.String&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=FluentCoding.String&version=1.0.3
                    
Install as a Cake Tool

FluentCoding

Set of functionalities to extend linq with more fluent capabilities This functionalities can be combined together to fluently manipulate an object

Or

Choose when pick the right object based on a predicate. By default Left when not default

var currentAddress = object.AddressDomicile.Or(object.AddressResidence);
var validData = object1.Or(object2, (subject)=> !subject.IsStillValid);
var mostRecentData = dataSource1.Or(dataSource2, (subject, orValue)=> orValue.LastUpdateTime > subject.LastUpdateTime);

Do

Update an object and return the object itself via Action or Function

identity.Do(_ => _.Name = "John")
        .Do(_ => _.Surname = "Smith");
private TypeT UpdateIdentity(TypeT identity)
{ 
  [...] //do stuff
  return updatedIdentity
}

var identitiesList = new List<Identity>();
identitiesList.Add(identity.Do(UpdateIdentity));

Equals

Expand the equality functions: EqualsTo, EqualsToAny, EquivalentTo, EquivalentToAny

EqualsTo

bool EqualityCheck(Identity p1, Identity p2) => p1.Pincode == p1.Pincode;ma � acceso?

Identity people1 = ReadFromDataBase(...);
Identity people2 = ReadFromDataBase(...);
Identity people3 = ReadFromDataBase(...);
Identity people4 = ReadFromDataBase(...);

people1.EqualsTo(people2, EqualityCheck);

people1.EqualsToAny(EqualityCheck, people2, people3, people4);
"XX".EqualsToAny("YY", "TT", "XX", "VV"); //when no specified an equality check, the framework Equals is used

EquivalentTo

bool EqualityCheck(Identity p1, Identity p2) => p1.Pincode == p1.Pincode;ma � acceso?

Tesla tesla = new Tesla() { ... };
Ferrari ferrari = new Ferrari() { ... };
Ferrari ferrari2 = new Ferrari() { ... };
Ferrari ferrari3 = new Ferrari() { ... };

tesla.EquivalentTo(ferrari, (t, f) => t.PlateNumber == f.PlateNumber);

tesla.EquivalentToAny((t, f) => t.PlateNumber == f.PlateNumber, ferrari, ferrari2, ferrari3);

IsNullOrDefault

Handy shorthand method to check if something is null or default

string.Empty.IsNullOrDefault(); //true
null.IsNullOrDefault(); //true
" ".IsNullOrDefault(); //true
" ".IsNullOrDefault(false); //false
objectInstance.IsNullOrDefault(); //false
public enum TestEnum { Enum1, Enum2 }
TestEnum.Enum1.IsNullOrDefault(); //true
TestEnum.Enum2.IsNullOrDefault(); //false
public static Func<bool> NullFunc = null;
public static Func<bool> NotNullFunc = () => true;
NullFunc.IsNullOrDefault(); //true
NotNullFunc.IsNullOrDefault(); //false

Is

Apply a boolean predicate to an object and obtain the preticate result along with the subject. Can be combined with other functions from this library in a fluent way

Address address = new Address() { ... }; 
(var isSatisfied, var checkSubject) = address.Is(_ => _.Country == "ITA");

var result = address.Is(_ => _.LastUpdate > DateTime.Now.AddYears(-5));
if(result.IsSatisfied) 
   result.Subject; /*do something*/

Map

Convert a Type into another one

Identity people = ReadFromDataBase(...);
var address = people.Map(p => new Address() {Street = p.Domicile, Country = p.BornCountry, ...});
Tesla ConvertToTesla(Ferrari f) 
{
    //[...] do something
    return teslaConversion;
}

TeslaSoftware ExtractSoftware(Tesla t) 
{
    //[...] do something
    return softwareFromTesla;
}

Ferrari ferrari = new Ferrari() { ... };
var sw = ferrari.Map(ConvertToTesla)
                .Map(ExtractSoftware);

Switch

Fluent version of the switch case: Switch, SwitchMap

Switch

Identity people = new Identity() { ... };
Identity ApiGetPeople(string pincode) { ... return people; }
Identity ApiGetPeopleAddress(people) { ... return peopleAddress; }

var updatedPeople =
people.Switch
(
    p => p,
    (p => p.LastUpdate < DateTime.Node.AddDays(-30) , p => ApiGetPeople(p.Pincode)),
    (p => p.LastUpdate < DateTime.Node.AddDays(-10) , p => p.Do(_ => _.Address = ApiGetPeopleAddress(p)))
)

SwitchMap

Identity people = new Identity() { ... };

var ageType = 
people.Switch
(
    p => Enum.Old,
    (p => p.YearsOld < 18 , p => Enum.Child),
    (p => p.YearsOld > 18  &&  p.YearsOld < 60 , p => Enum.Adult)
);

When

Apply one or more checks on the subjects and then apply and Action or a Function only when all the checks are satisfied

When base class

var car = LoadCarData(...);

When<Car> result = car.When(c => c.Type == "Ferrari");

result.IsSuccess; // the predicate result
result.Subject; //the predicate subject

When.Then

var car = LoadCarData(...);
c.Insurance = InsuranceType.LowBudget;

car.When(c => c.Type == "Ferrari")   
   .Then(c => c.Insurance = InsuranceType.Luxury);

When.Or.Then

var car = LoadCarData(...);
c.Insurance = InsuranceType.LowBudget;

car.When(c => c.Type == "Ferrari")
   .OrWhen(c => c.Type == "Lamborghini")
   .Then(c => c.Insurance = InsuranceType.Luxury);

When.Or.And.Then

var car = LoadCarData(...);
c.Insurance = InsuranceType.LowBudget;

car.When(c => c.Type == "Ferrari")
   .OrWhen(c => c.Type == "Lamborghini")
   .AndWhen(c => c.MarketPrice >= 180000)
   .Then(c => c.Insurance = InsuranceType.Luxury);

When.ThenMap only when True

var car = LoadCarData(...);
Ferrari ConvertToFerrari(Car car) 
{
 //[...] do something
 return ferrari; 
}

//when
(Ferrari ferrari, Car subject) = car.When(c => c.Type == "Ferrari")      
                                    .ThenMap(ConvertToFerrari);

When.ThenMap when True or When False

var car = LoadCarData(...);
Ferrari ConvertToFerrari(Car car) 
{
 //[...] do something
 return ferrari; 
}

Ferrari CreateNewFerrari(Car car)
{
 //[...] do something
 return newFerrari; 
}

//when
var ferrari = car.When(c => c.Type == "Ferrari")      
                 .ThenMap(ConvertToFerrari, CreateNewFerrari);

TryCatch

Draft Inline wrap methods for the Try{}Catch{}

Try base class

Try to do something and return a context with all the information

Car LoadCarData(string licensPlate)
{
 //[...] do something
 return car; 
}

var tryResult = "xxxxx".Try(LoadCarData);
tryResult.IsSuccesful; //true or false
tryResult.Subject; //the input string licensePlace
tryResult.Result; //the Car object loader
tryResult.Error; //the Exception raised when loading the car data
Car LoadCarData(string licensePlate)
{
 //[...] do something
 return car; 
}

CustomError ManageException(String licensePlate, Exception e) => new CustomError(e.Messge, licensePlate);

var tryResult = "carLicensePlate".Try(LoadCarData, ManageException);
tryResult.IsSuccesful; //true or false
tryResult.Subject; //the input string licensePlace
tryResult.Result; //the Car object loader
tryResult.Error; //the CustomError returned by ManageException

Try.OnSuccess or Try.OnFail

Try to do something and when ok do something else

Car LoadCarData(string licensPlate)
{
 //[...] do something
 return car; 
}
List<CarComponent> DisassembleCar(Car car)
{
 //[...] do something
 return carComponents; 
}

(var Components, var tryCatchContext) = "xxxxx".Try(LoadCarData)
                                               .OnSuccess(DisassembleCar);                       
Components; //the disassembled car components ONLY WHEN no exception occurred, default of List<CarComponent> otherwise
tryCatchContext; //the TryCatch class from the previous example, ALWAYS returned
Car LoadCarData(string licensPlate)
{
 //[...] do something
 return car; 
}
CustomError ManageException(String licensePlate, Exception e) => new CustomError(e.Messge, licensePlate);

List<Car> availableCar = new List<Car>();

(var error, var tryCatchContext) = "xxxxx".Try(plate => availableCar.Add(LoadCarData(plate))
                                          .OnFail(ManageException);
                       
error; //the CustomError ONLY WHEN and exception occurred, default of CustomError otherwise
tryCatchContext; //the TryCatch class from the previous example, ALWAYS returned

Try.Then

Try to do something and then manage the success or the fail result

Car LoadCarData(string licensPlate)
{
 //[...] do something
 return car; 
}
bool AddCarToStock(Car car) 
{
 //[...] do something
 return true; 
}
bool TraceCarError(string plate, Exception e) 
{
 //[...] do something
 return true; 
}

CustomError ManageException(String licensePlate, Exception e) => new CustomError(e.Messge, licensePlate);

"xxxxx".Try(LoadCarData)
       .Then(AddCarToStock, TraceCarError);                       

TryTo

Try to do something or manage the exception, the output type can differ from the subject input type

var date = "2022-12-29".TryTo(DateTime.Parse, (c, ex) => DateTime.MinValue);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.1.3 752 4/3/2023
2.1.1 367 3/16/2023
2.1.0 379 2/24/2023
2.0.0 431 1/11/2023
1.2.1 412 1/5/2023
1.2.0 425 1/5/2023
1.1.0 413 1/3/2023
1.0.4 420 1/2/2023
1.0.0 421 1/2/2023

first release