FluentStructures 1.0.1

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

// Install FluentStructures as a Cake Tool
#tool nuget:?package=FluentStructures&version=1.0.1                

FluentStructures

This project provides a set of fluent APIs to simplify the handling of structs in .NET.

You spent too much time centering stuff with X1 + ((Width1 - Width2) / 2).

Use cases

Setting properties with With...

The extensions methods With... and WithAdditional... provide expressive ways to get a copy of a struct with absolute values or relative value additions.

//   (p1)───────────────────────────────(p2)
//                                       │
//                                       │
//                                       │   +50px
//                                       │
//                                       │
//                         (p4)─────────(p3)
//                               -33px

// traditional
var p1 = new Point(10, 10);
var p2 = new Point(100, p1.Y);
var p3 = new Point(p2.X, p2.Y + 50);
var p4 = new Point(p3.X - 33, p3.Y);

// fluent
p1 = new Point(10, 10);
p2 = p1.WithX(100);             // absolute
p3 = p2.WithAdditionalY(50);    // relative
p4 = p3.WithAdditionalX(-33);

Emphasizing the intent over simple calculations

This project does not only add fluent extensions to set properties, it also comes with tailored extension methods to emphasize the intent when working with structs. Simple and expressive code instead of calculations that have to be thought through every time they get rediscovered.

The Rectangle (and RectangleF) gets an extension method to find its landmarks (corner stones or the center point) easily ...

//    ┌──────────────────────────────────┐
//    │                                  │
//    │                                  │
//    │              (p1)                │
//    │                                  │
//    │                                  │
//    └──────────────(p2)────────────────┘


// traditional
var p1 = new Point(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
var p2 = new Point(rect.Left + (rect.Width / 2), rect.Bottom);

// fluent
p1 = rect.GetLandmark(ContentAlignment.MiddleCenter);
p2 = rect.GetLandmark(ContentAlignment.BottomCenter);

... while Embed() takes another rectangle or size to be embedded and returns the corresponding bounds depending on the defined alignment.

//    ┌──────────────────────────────────┐
//    │                                  │
//    │                         ┌────┐   │
//    │                         │    │   │   <-- 10px padding
//    │                         └────┘   │
//    │                                  │
//    └──────────────────────────────────┘

var cellBounds = new Rectangle(100, 100, 300, 150);
var userImage = new Bitmap(30, 30);

// traditional
var userImageBounds = new Rectangle(
    cellBounds.Right - userImage.Width - 10,
    cellBounds.Y + ((cellBounds.Height - userImage.Height) / 2),
    userImage.Width,
    userImage.Height);

// fluent
userImageBounds = cellBounds
    .Embed(userImage.Size, ContentAlignment.MiddleRight)
    .WithAdditionalLeft(-10);

Scope

This project currently adds extension methods to structs of the System.Drawing namespace like Color, Point, Rectangle and so on. More structs might be added over time, pull requests always welcome.


Model icons created by Flowicon on Flaticon

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.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 was computed.  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.
  • .NETStandard 2.0

    • 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.1 124 5/21/2024
1.0.0 161 5/19/2023